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

poplight

v1.1.6

Published

A lightbox module for template rendering

Downloads

20

Readme

POPLIGHT

A small and simple lightbox module built for both handlebars and static templating. No ugly pre styles included which means it's totally up to you to customize!

Demo

You can find a working demo here

Build status

Build Status JavaScript Style Guide

Install

$ npm install poplight

with yarn

$ yarn add poplight

Initiate lightbox

Create a new lightbox by calling the module constructor. The constructor takes two parameters. The initiation will generate a new element to the DOM which can be styled just the way you want.

  1. Target element. A DOM element which will serve as the click handler for the "open lightbox" event.
  2. Options. See documentation below.
const lightbox = new PopLight(document.querySelector('button'), {})

Usage

 import PopLight from 'poplight'

 const targetElement = document.querySelector('button');

 const options = {
  template: `<div class="lightbox"> <h1> POP! </h1> </div>`,
  lightboxSelectorClose: '.button--close',
  onLoadCallback: () => { console.log('popped') },
 }

 new PopLight(targetElement, options);

Note: The target element can also be null. If null, use the poplight.open() function to trigger the lightbox.

Usage with handlebars

Handlebars template

<script id="handlebars-demo" type="text/x-handlebars-template">
   <div>
      Hello {name}, this is a demo lightbox!
   </div>
</script>
 import PopLight from 'poplight'

 const targetElement = document.querySelector('button');
 const template = document.getElementById('handlebars-demo');
 const compiledTemplate = Handlebars.compile(template.innerHTML);

 const options = {
  template: compiledTemplate,
  data: { name: 'Elina' },
  handlebars: true,
 }

 new PopLight(targetElement, options);

Asynchronous example

Handlebars template. Note: Handlebars must be included in project. Download here

<script id="handlebars-demo" type="text/x-handlebars-template">
   <div>
      <h1>{{Title}}</h1>
      <h3> {{Subtitle}} </h3>
      <p> {{ content }} </p>
   </div>
</script>

<button data-post="2"> Get post! </button>
 import PopLight from 'poplight';

 const button = document.querySelector('button');
 const template = document.getElementById('handlebars-demo');
 const compiledTemplate = Handlebars.compile(template.innerHTML);

 button.addEventListener('click', (e) => {
   const endpoint = e.target.dataset.post;

   const options = {
    template: compiledTemplate,
    async: true,
    api: 'http://api.mypage.com/posts/' + endpoint,
    handlebars: true,
   }

   const lightbox = new PopLight(null, options);
   lightbox.open();
 })

Options

| property | type | default | | ------------- |:-------------:| -----:| | element | string | div | | selectorClose | string | [data-lb-close] | | lightboxSelector | string | lightbox | | lightboxActiveClass | string | lightbox--active | | lightboxSelectorVariant | string | '' | | template | function/string (depending on template style)| hello | | handlebars | boolean | false | | data | object | {} | | async | boolean | false | | api | string | '' | | method | string | 'GET' | | body | string | '' | | onLoadCallback | function | () => {} |

API

Open: poplight.open()

Close: poplight.close()