Skip to content

milesbarr/enhancejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enhance.js

A lightweight JavaScript library that provides progressive enhancements for HTML forms and user interactions. This library adds functionality while maintaining zero dependencies and graceful degradation.

Setup

Include the library in your HTML file:

<script src="enhance.js" async defer></script>

For graceful degradation for users with JavaScript disabled, copy noscript.html into the <head> section of your HTML file.

Usage

Form Confirmations

Add confirmation dialogs to forms or form submission buttons:

<form data-confirm="Are you sure?">
  <!-- Form content -->
  <button data-formconfirm="Are you sure?">Submit</button>
</form>

Unsaved Changes Warning

Warn users about unsaved changes in forms:

<form data-unsaved-changes-warning>
  <!-- Form content -->
</form>

Share Buttons

Add share functionality:

<button type="button" data-share>Share</button>

Copy Buttons

Add copy-to-clipboard functionality:

<input type="text" id="text">
<button type="button" data-copy="text">Copy</button>

Image File Previews

Preview images for file inputs:

<input type="file" id="upload">
<img data-preview-for="upload">

Character Counter

Display the remaining character count for text inputs:

<textarea id="message" maxlength="100"></textarea>
<span data-chars-remaining-for="message"></span>

Auto-Resizable Textareas

Automatically adjust textarea height based on content:

<textarea data-auto-resize></textarea>

Smooth Scrolling

Automatic smooth scrolling to anchor links:

<a href="#section">Go to section</a>
<div id="section">Content</div>

Invalid Inputs

Automatically reset aria-invalid attributes:

<input type="text" aria-invalid="true">

File Drag-and-Drop

Add file drag-and-drop functionality:

<label data-drop-zone>
  <input type="file">
</label>

AJAX Support

Use AJAX for form submissions and link navigation:

<div id="page">
  <a href="." data-ajax-replace="page">Refresh page</a>
</div>

Graceful Degradation

All features are implemented as progressive enhancements, meaning the basic functionality will work even if JavaScript is disabled.

License

This project is licensed under the MIT License.

About

A lightweight JavaScript library that provides progressive enhancements for HTML.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published