Annotate fields to be persisted on navigation away from the current page
Перейти к файлу
Ned Schwartz cf1d99b57d add chromium 2022-02-16 23:17:35 +00:00
.github/workflows Build with GitHub Actions 2020-09-14 09:16:20 -06:00
src Mutate variable instead of copying to new variable 2021-04-23 10:47:23 +01:00
test Avoid changing existing tests 2021-04-22 16:24:39 -06:00
.gitignore add support files to build and test 2019-02-06 18:13:36 +00:00
CODEOWNERS Create CODEOWNERS 2021-04-22 13:06:01 +01:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2019-02-18 14:35:47 +00:00
CONTRIBUTING.md Create CONTRIBUTING.md 2019-02-18 14:34:54 +00:00
LICENSE Update development dependencies 2020-04-10 09:17:21 -06:00
README.md Fix typos in readme 2021-10-05 10:56:43 +00:00
karma.config.js Replace Babel + Flow with TypeScript 2020-04-10 10:46:15 -06:00
package-lock.json add chromium 2022-02-16 23:17:35 +00:00
package.json add chromium 2022-02-16 23:17:35 +00:00
tsconfig.json Replace Babel + Flow with TypeScript 2020-04-10 10:46:15 -06:00

README.md

Session Resume

Annotate fields to be persisted on navigation away from the current page. Fields will be automatically restored when the user revisits the page again in their current browser session (excludes separate tabs).

Not designed for persisted crash recovery.

Installation

$ npm install @github/session-resume

Usage

HTML

<form>
  <input id="new-comment" class="js-session-resumable"/>
</form>

JS

import {persistResumableFields, restoreResumableFields, setForm} from '@github/session-resume'

function getPageID() {
  return window.location.pathname
}

// Listen for all form submit events and to see if their default submission
// behavior is invoked.
window.addEventListener('submit', setForm, {capture: true})

// Resume field content on regular page loads.
window.addEventListener('pageshow', function() {
  restoreResumableFields(getPageID())
})

// Persist resumable fields when page is unloaded
window.addEventListener('pagehide', function() {
  persistResumableFields(getPageID())
})

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.