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

dialogr

v1.2.0

Published

Vanilla JS modal/popup micro-library.

Downloads

5

Readme

Dialogr

About

This is a lightbox/modal library that uses only plain ol' JavaScript and native HTML elements, namely the dialog element. Given that, there is still very limited support for the dialog element (see canisee. So you probably shouldn't use this in a production setting (yet)

How To Use

Using is super easy. There are two steps to using dialogr, first you need to require and set it up:

const Dialogr = require('dialogr');
Dialogr.setup();

That gets the styles and all that good stuff in your page.

Next, there are only two things you need when calling dialogr:

  • The elements that will trigger the modal
  • An options object.

Note: when adding a trigger, there are two functions you can call. The old function was Dialogr.dialogr(...), however there is a new alias that should be used: Dialogr.addTrigger(...).

There are only a couple options:

  • gallery
  • type
  • content
  • openAction

The type option can be either 'image' or 'html'. The default value is 'html'. The gallery option is a boolean for whether there should be gallery controls on the lightbox, this is only available for 'image' types. Content is only available when the lightbox type is 'html'. As the name suggests... it accepts html. The openAction option sets the user action to open the dialog (click, dblclick, etc).

Here's an example:

let galleryImages = document.querySelectorAll('.gallery-image');
Dialogr.addTrigger(galleryImages, {
  gallery: true,
  type: 'image',
});

Here's an example of an HTML type lightbox:

let htmlDialogTrigger = document.querySelectorAll('.js-trigger-dialog');
Dialogr.addTrigger(htmlDialogTrigger, {
  content: `<p>This is some HTML content!</p>
    <p>Warm fuzzy feelings</p>`,
});

It's possible to open a modal without adding any triggers to it - simply pass the boolean false in place of an array of triggers and it will immediately open:

Dialogr.addTrigger(false, {
  content: `<p>This is some HTML content that's opened automatically!</p>`,
});

Any element can be image modal triggers, they will need either a src attribute OR a data attribute dialogr-src. Here's an example of a button that opens an image modal (would work with the first example):

<button class="gallery-image" data-dialogr-src="https://www.nasa.gov/sites/default/files/thumbnails/image/discover_missions_banner.jpg">I open an image too!</button>

It's also possible to add captions to images displayed in the lightbox, there are two way to do it:

  1. Add the data-dialogr-caption attribute to the image that gets passed into dialogr
  2. If the image is part of a figure and has a figcaption as a sibling, the figcaption's text will be pulled into the dialog.