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

splidebox

v1.0.10

Published

Splidebox is a lightweight JavaScript library for creating customisable image lightboxes using Splide.js.

Downloads

20

Readme

Splidebox is a lightweight JavaScript library for creating customisable image lightboxes using Splide.js. Easily integrate image galleries into your web applications with minimal setup.

This project wouldn't be possible without:

  • Naotoshi Fujita, the developer behind Splide
  • cure53, the developer behind DOMPurify
  • Tailwind Labs, the developers behind Tailwind.

Also, an honorary mention of Gausarts, the developer behind a Drupal extension that shares the same name Splidebox - (https://www.drupal.org/project/splidebox)

Any contributions, suggestions, or feedback is welcome.

Preview:

Dependencies:

Theses are compiled within dist/js/splidebox.js and dist/js/splidebox.min.js, or imported in src/js/splidebox.js

  • Splide (Lightweight Carousel library) - https://splidejs.com/
  • Tailwind CSS - https://tailwindcss.com/docs/installation
  • DOMPurify (for security when iterating through and rendering images) - https://github.com/cure53/DOMPurify

Installation Options:

There's a few of ways that you can install it.

Use the CDN from jsDeliver:

splidebox.js:

<script src="https://cdn.jsdelivr.net/npm/splidebox/dist/js/splidebox.js"></script>

splidebox.min.js:

<script src="https://cdn.jsdelivr.net/npm/splidebox/dist/js/splidebox.min.js"></script>

Download, clone, or fork this repo and use the splidebox.js under:

  • src/js or dist/js

run npm install splidebox and use either:

src/js/splidebox.js, dist/js/splidebox.js or dist/js/splidebox.min.js

Supported Options

  • background: (object)

    • enable: (boolean) (default: true)
    • backgroundColor: (string) (default: 'rgba(0, 0, 0, 0.7)')
  • closeWithEscapeKey: (boolean) (default: true)

  • openButtonSelector: (string) (default: 'open-splidebox')

  • closeButtonSelector: (string) (default: 'close-splidebox')

  • splideboxLabel: (string) (default: 'An image carousel.')

    • Used to set the aria-label attribute for the Splide carousel.
  • images: (array) (default: [])

    • Array of image URLs to display in the carousel.
  • splideOptions: (object)

    • Can be used to parse options from Splide.js (https://splidejs.com/guides/options/).
    • Not all options have been tested. Please report any bugs encountered.

New Features:

Splidebox will now automatically grab images from the attribute data-splidebox-images from the specified openButtonSelector

If left blank, it'll use the images specified in the images option when initialising Splidebox.

This means that you can have multiple elements with the same openButtonSelector class, yet load different images, all on the same markup for the lightbox (rather than having multiple containers for different lightboxes.)

<div class="image cursor-pointer"
     data-splidebox-images='["https://placehold.co/100x100","https://placehold.co/150x150","https://placehold.co/200x200"]'>
     
    <img class="w-[250px] w-[250px] m-auto object-cover"
         src="https://placehold.co/300x300"
         alt="Image"/>
</div>

Example:

You'll need to instantiate the class when building a Splidebox. It's best to do this after the DOM content has loaded:


document.addEventListener('DOMContentLoaded', () => {

    const lightboxWrapper = document.getElementById('lightbox-wrapper');

    let imageArray = [
        'https://placehold.co/300x300',
        'https://placehold.co/350x350',
        'https://placehold.co/400x400',
    ]

    lightboxWrapper.Splidebox({
        background: {
            enable: true, // You don't need to specify this.
            backgroundColor: 'rgba(0, 0, 0, 0.4)',
        },
        closeWithEscapeKey: false,
        openButtonSelector: '.image',
        closeButtonSelector: '#new_close_button',
        splideboxLabel: 'Product lightbox',
        images: imageArray,
        splideOptions: {
            type: 'loop',
            pagination: 'false',
            // Any further options from Splide (https://splidejs.com/guides/options/)
        }
    })

});