- Notifications
You must be signed in to change notification settings - Fork13
Annotate fields to be persisted on navigation away from the current page
License
github/session-resume
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Annotate fields to be persisted on navigation away from the current page.Fields will be automatically restored when the user revisits the pageagain in their current browser session (excludes separate tabs).
Not designed for persisted crash recovery.
$ npm install @github/session-resume<form><inputid="new-comment"class="js-session-resumable"/></form>
import{persistResumableFields,restoreResumableFields,setForm}from'@github/session-resume'functiongetPageID(){returnwindow.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 unloadedwindow.addEventListener('pagehide',function(){persistResumableFields(getPageID())})
TherestoreResumableFields(id: string, options) function supports optional configurations:
storage:-Storageinstance (defaults towindow.sessionStorage)keyPrefix:-stringprepended onto the storage key (defaults to"session-resume")
ThepersistResumableFields(id: string, options) function supports optional configurations:
storage:-Storageinstance (defaults towindow.sessionStorage)storageFilter:-(field: HTMLInputElement | HTMLTextAreaElement) => booleanpredicate to determine whether or not to store a field (defaults to(field) => field.checked !== field.defaultChecked)for checkbox and radio buttons,(field) => field.value !== field.defaultValueotherwise)keyPrefix:-stringprepended onto the storage key (defaults to"session-resume")scope:-ParentNodeused to query field elements (defaults todocument)selector:-stringused to query field elements (defaults to".js-session-resumable")fields:-NodeList | Node[]provide field elements as an alternative to querying (defaults tooptions.scope.querySelectorAll(options.selector))
Note: Whenfields is specified,scope andselectors will be ignored.
npm installnpm testDistributed under the MIT license. See LICENSE for details.
About
Annotate fields to be persisted on navigation away from the current page
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors12
Uh oh!
There was an error while loading.Please reload this page.