npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jeffbarrera/jbmodal

v1.0.1

Published

Lightweight, vanilla-JS plugin to handle modal interactions

Downloads

2

Readme

jb-slider

Installation | Usage | Options | Methods

A lightweight (2KB minified), vanilla javascript modal/popup plugin. This simply adds/removes element classes as needed, letting you specify the design, animation, etc of the modal as desired with CSS.

Installation

With NPM:


npm i @jeffbarrera/jbmodal

Or download manually and include jbModal.min.js in your HTML file.

Dependencies

JBSlider has no dependencies, unless you need to support older browsers that don't natively implement classList. If you do, install the classList.js polyfill that extends support back to IE 7.

Usage

Initialize a new modal


modal = new JBModal({
	modalSelector: '.modal',
	openButtonSelector: '.modal--open',
	closeButtonSelector: '.modal__close-btn',
	hidingClass: 'modal--hiding',
	hiddenClass: 'modal--hidden'
});

See below for the full list of options that can be passed in, and the defaults.

Opening the modal

The modal will open when an element matching the openButtonSelector is clicked. If you want to open the modal programmatically:


modal.open();

Closing the modal

The modal will close when an element matching the closeButtonSelector is clicked. If closeWithEsc is set to true, the modal will also close when the esc key is pressed.

If you want to close the modal programmatically:


modal.close();

Options

These options can be passed into the new JBSlider() constructor:


modal = new JBModal({
	modalSelector: '.modal',
	openButtonSelector: '.modal--open',
	closeButtonSelector: '.modal__close-btn',
	hidingClass: 'modal--hiding',
	hiddenClass: 'modal--hidden',
	openButtonOpenClass: null,
	closeWithEsc: true,
	transitionLength: 300
});

modalSelector

Type: String

Default: .modal

A CSS selector for the modal's wrapper element. Must be a string that can be passed into document.querySelector();. This should be a unique selector, otherwise only the first matching element will be used. To create multiple modals on the same page, use two different selectors.

openButtonSelector

Type: String

Default: .modal--open

A CSS selector for buttons/links that should open the modal when clicked. Must be a string that can be passed into sliderWrapper.querySelectorAll(); .

closeButtonSelector

Type: String

Default: .modal__close-btn

A CSS selector for buttons/links that should close the modal when clicked. Must be a string that can be passed into sliderWrapper.querySelectorAll(); .

hidingClass

Type: String

Default: modal--hiding

JBSlider assumes that by default, the modal is styled to be visible. The hidingClass is applied while the modal is closing, and should be styled to that CSS transitions smoothly animate from the open to closed state. If the modal should begin closed, add both the hidingClass and hiddenClass to your HTML element.

hiddenClass

Type: String

Default: modal--hidden

The class that should be applied once the transition animation is completed. It is added after the transitionLength time has expired. Use this to prevent an invisible modal from overlapping other content, such as by setting:


z-index: -1;
height: 0;
padding: 0;

hidingClass

Type: String

Default: modal--hiding

JBSlider assumes that by default, the modal is styled to be visible. The hidingClass is applied while the modal is closing, and should be styled to that CSS transitions smoothly animate from the open to closed state. If the modal should begin closed, add both the hidingClass and hiddenClass to your HTML element.

openButtonOpenClass

Type: String

Default: null

If set, this class will be added to the open button while the modal is open. Use if you want the open button to visually indicate that the modal is open in some way.

closeWithEsc

Type: Boolean

Default: true

If set to true, the modal will close when the esc key is pressed.

transitionLength

Type: Integer

Default: 300

The delay before the hiddenClass is applied. This shuuld be at least as long as the CSS transition length, but not much longer.

Element references

You can access slider elements as follows:


modal.modal; // the modal element
modal.openButtons; // an array of open buttons
modal.closeButtons; // an array of close buttons
modal.isOpen; // boolean indicating if the modal is currently open