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

@zaneray/modal-extras

v1.0.14

Published

Modal extras for bootstrap framework

Downloads

38

Readme

@zaneray/modal-extras

Getting Started

Modal Extras can be used in an project that implements Bootstrap modal

yarn add @zaneray/modal-extras

and then import the functions you wish to use through ES6 imports:

import * as modalextras from '@zaneray/modal-extras`;

If you prefer not to use a package manager, you can download the latest version of Modal Extras and include it in your project manually from the following links:

These files make Modal Extras accessible via the Zaneray.bootstrap.modal global variable.

Browser Support

Modal Extras uses two APIs not available to legacy browsers, Fetch and Promise. If you wish to support legacy browsers, make sure you add the following dependencies to your project:

yarn add unfetch es6-promise

and then import them before you import Modal Extras:

// Only need to import these once
import 'unfetch/polyfill';
import 'es6-promise/auto';

// Import @zaneray/modal-extras anywhere you need it
import * as modalextras from '@zaneray/modal-extras';

Methods

onLoad()

Finds all data-toggle elements on the page and binds them to the proper methods based on their value

modalextras.onLoad();

generateModalTemplate(html, clazz)

Injects the dynamic-modal HTML wrapper to the begining of the body and binds a modal.bs.hide method to remove it from the DOM

modalextras.generateModalTemplate('<div>content</div>', '');

Binding Usage

Inline Html

Auto bind a link on the page to load content on the page to a modal. To avoid duplicate DOM id's on the page when the content is copied in to the modal, the parent element ID is changed to [id]-modal. If you're relying on this id for styling, ensure you also include this selector in your css.

<a href="#" data-toggle="modal-html" data-id="id-1234">Open HTML modal by ID</a>
<div id="id-1234">Content to load in a modal</div>

AJAX Content

By default you can specify a URL and all of that URL will be loaded to the page. Specify data-toggle of modal-ajax and the script will grab the URL in the href. This works fine for snippets of HTML but in demo you can see that it loads all of the image from /includes/ajax.html including the header and footer.

<a href="includes/ajax.html" data-toggle="modal-ajax">Open Ajax Modal</a>

Load a page with an optional selector

Optionally you can specify an id and the script will load the whole page and display the results specified in the data-id selector.

<a href="includes/ajax.html" data-toggle="modal-ajax" data-id="wrapper">Open Ajax Modal and inject with Element id="wrapper" from response</a>

By default, the outerHTML of the wrapper is injected in to the modal. You can change that to the innerHTML by adding data-unwrap="true"

<a href="includes/ajax.html" data-toggle="modal-ajax" data-id="wrapper" data-unwrap="true">Open Ajax Modal and inject innerHTML of Element id="wrapper" from response</a>

Modal Images

Specify a data-toggle attribute of modal-image to load the image in the href of an anchor link in a modal window.

<a href="http://www.zaneray.com/proto/images/flatheadsunset.jpg" data-toggle="modal-image">Open horizontal Image Modal </a>

Additional Data Attributes for Images

Creating a gallery with prev/next links. When a data-gallery link is clicked, spans will be injected in to the bottom of the modal-content and all links on the page with the same data-gallery value will be cycled through when clicked or swiped

<span class='global-arrow prev-arrow'></span><span class='global-arrow next-arrow'></span>

Attribute | Example ----------|------------- data-gallery | modal-gallery-example data-caption | this image has a caption data-link | http://www.google.com

<a href="http://www.zaneray.com/proto/images/two-med.jpg" data-toggle="modal-image" data-gallery="modal-gallery-example" data-caption="This image has a caption">Open Image as part of a Modal Gallery</a>
<a href="http://www.zaneray.com/proto/images/fireotm.jpg" data-toggle="modal-image" data-gallery="modal-gallery-example" data-caption="This image has a caption and link" data-link="www.zaneray.com">Open Image as part of a Modal Gallery</a><
<a href="http://www.zaneray.com/proto/images/flatheadsunset.jpg" data-toggle="modal-image" data-gallery="modal-gallery-example">Open Image as part of a Modal Gallery</a>

Instagram details for an image (data-instagram)

When data-instagram is found on the link, instead of injecting the data-caption, it will use the following data attributes to create HTML that can be styled.

  • data-userphoto
  • data-username
  • data-location
  • data-likes
  • data-caption
  • data-link

The following HTML will be appended to the modal-content element

<div class='modal-image-instagram-container'>
  <div class='user-section'>
    <img src='${el.dataset.userphoto}' class='instagram-userphoto' />
    <div class='user-info'>
      <span class='username'>${el.dataset.username}</span>
      <span class='location'>${el.dataset.location}</span>
    </div>
    <a href=${el.dataset.link} class='btn btn-sm btn-instagram' target='_blank'>Follow</a>
  </div>
  <span class='image-likes'>${el.dataset.likes}</span>
  <span class='image-caption'>${el.dataset.caption}</span>
</div>

Modal Videos

Specify a data-toggle of modal-video to dynamically load the video. It is required to specify a data-key as well as a data-source which at the moment only includes Youtube and Vimeo. It is recommended to make the href a link to the URL of the video for Accessbility reasons.

<a href="https://vimeo.com/74980365" data-key="74980365" data-source="Vimeo" data-toggle="modal-video">Open Vimeo Video</a>

Additional Classes

If you need to override the styling of a modal window you can always specify a custom class with data-class attribute.

<a href="http://www.zaneray.com/proto/images/flatheadsunset.jpg" data-toggle="modal-image" data-class="my-additional-class">Open Image with Custom Class </a>

Closing the modal window

Pressing escape will close the Modal window for all dynamically created modal windows not including standard inline Bootstrap Modals. Click outside the modal window will also close the modal.

The hidden.bs.modal event is bound to remove the modal from the DOM upon close