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

jquery.modal

v0.2.4

Published

Simple jQuery modal dialog.

Downloads

130

Readme

Synopsis

This is a small-ish (1.9kB minified, 0.9kB gzipped) modal plugin for jQuery. While most modal plugins try to handle all interactions themselves, jQuery.modal only provides the modal dialog and overlay.

Basic usage example

Try it on jsfiddle.

var $modal = $('<div/>')
  .text('Hello World! Click to dismiss.')
  .css({color: 'red', background: 'white', cursor: 'pointer'})
  .modal()
  .modal('open')
  .on('click', function() {
    $modal.modal('close');
  });

More realistic example

Try it on jsfiddle.

HTML

<a class="open-btn">Open</a>
<div class="my-dialog">
  <h1>Hello World!</h1>
  <a class="close-btn">Close</a>
</div>

CSS

.my-dialog {
  border: 2px solid black;
  background-color: papayawhip;
  color: red;
  padding: 5px;
}
.open-btn, .close-btn {
    border: 1px solid black;
    cursor: pointer;
}

JavaScript

var $dialog = $('.my-dialog').modal();
$dialog.on('click', '.close-btn', function(e) {
  e.preventDefault();
  $dialog.modal('close');
});
$('.open-btn').on('click', function(e) {
  e.preventDefault();
  $dialog.modal('open');
});

API

modal([options])

Wraps the matched content in a modal dialog intialized with the given options.

NOTE: The matched content will be removed from the page if necessary.

modal('open')

Reveals the overlay and modal dialog.

modal('close')

Hides the modal dialog and overlay.

modal('option', name)

Returns the current value of the option name for this modal dialog.

modal('option', name, value)

Sets the value of the option name for this modal dialog to the given value. Returns the new value.

modal.defaults

The default options used by new modal dialogs.

NOTE: Changes will be reflected by existing modal dialogs unless the option was set explicitly on initialization or with modal('option', name, value). This is intentional.

showFn(callback)

Function to be called in order to reveal the dialog. Must call the passed callback when the animation is complete.

Default:

function(callback) {
  this.fadeIn(200, callback);
}

hideFn(callback)

Function to be called in order to hide the dialog. Must call the passed callback when the animation is complete.

Default:

function(callback) {
  this.fadeOut(200, callback);
}

modal.overlay

Options used by the overlay.

showFn(callback)

Function to be called in order to reveal the overlay. Must call the passed callback when the animation is complete.

Default:

function(callback) {
  this.fadeTo(200, 0.5, callback);
}

hideFn(callback)

Function to be called in order to hide the overlay. Must call the passed callback when the animation is complete.

Default:

function(callback) {
  this.fadeOut(1, callback);
}

Acknowledgements

Inspired by edwardhotchkiss' jQuery.leanerModal, which is in turn based on finelysliced's jQuery.leanModal.

License

The MIT/Expat license.