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

@claviska/jquery-alertable

v1.0.2

Published

Minimal alert and confirmation alternatives.

Downloads

88

Readme

jquery.alertable.js - Minimal alert, confirm, and prompt replacements.

Developed by Cory LaViska for A Beautiful Site, LLC

Licensed under the MIT license: http://opensource.org/licenses/MIT

Overview:

This plugin provides a minimal, lightweight, and customizable alternative to window.alert() and window.confirm(). It's flexible enough to mold to your application's existing stylesheet and markup.

Features:

  • Simple syntax:
    • $.alertable.alert('Howdy!')
    • $.alertable.confirm('You sure?').then(function() { ... })
    • $.alertable.prompt('How many?').then(function(data) { ... })
  • Minimal default styles; easy to customize or write your own.
  • Show/hide hooks for adding custom animation (works well with Velocity.js).
  • Prevents focus from leaving the modal.
  • Returns promise-compatible (jQuery deferred) for ok/cancel actions.
  • Compact! (about 180 lines)

Demo

A quick demo can be found on CodePen: http://codepen.io/claviska/pen/mPNWxy

A local demo can be found in example.html.

Installing

Include the minified version of this plugin in your project or install via NPM:

npm install --save @claviska/jquery-alertable

Using the plugin

Example alerts:

// Basic example
$.alertable.alert('Howdy!');

// Example with action when the modal is dismissed
$.alertable.alert('Howdy!').always(function() {
    // Modal was dismissed
});

Example confirmations:

// Basic example
$.alertable.confirm('You sure?').then(function() {
    // OK was selected
});

// Example with then/always
$.alertable.confirm('You sure?').then(function() {
    // OK was selected
}, function() {
    // Cancel was selected
}).always(function() {
    // Modal was dismissed
});

Example prompts:

// Basic example
$.alertable.prompt('How many?').then(function(data) {
    // Prompt was submitted
});

// Example with then/always
$.alertable.prompt('How many?').then(function(data) {
    // Prompt was submitted
}, function() {
    // Prompt was canceled
}).always(function() {
    // Modal was dismissed
});

Important: Unlike window.alert(), window.confirm(), and window.prompt(), using this plugin will not cause execution of the script to stop while the modal is open. This behavior is not possible to emulate with a plugin nor is it desirable in modern web applications.

Options

Pass options as the second argument of any method:

$.alertable.alert('Howdy!', {
    optionName: optionValue,
    ...
});

$.alertable.confirm('You sure?', {
    optionName: optionValue,
    ...
});

$.alertable.prompt('How many?', {
    optionName: optionValue,
    ...
});

Available options:

  • container: The container to append the modal to. Defaults to 'body'.

  • html: Whether or not your message contains HTML. Defaults to false.

  • cancelButton: HTML to use for the reject button. Default value:

<button class="alertable-cancel" type="button">Cancel</button>
  • okButton: HTML to use for the resolve button. Default value:
<button class="alertable-ok" type="button">OK</button>
  • overlay: HTML to use for the overlay. Default value:
<div class="alertable-overlay"></div>
  • prompt: HTML to use for the prompt body. All inputs contained in this HTML will be serialized and returned when the prompt is submitted. Default value:
<input class="alertable-input" type="text" name="value">
  • modal: HTML to use for the modal. Default value:
<div class="alertable">
    <div class="alertable-message"></div>
    <div class="alertable-buttons"></div>
</div>
  • hide: Function for hiding the modal and overlay. Use this.modal and this.overlay to reference the modal and overlay elements. Default value:
$(this.modal).add(this.overlay).fadeOut(100);
  • show: Function for showing the modal and overlay. Use this.modal and this.overlay to reference the modal and overlay elements. Default value:
$(this.modal).add(this.overlay).fadeIn(100);

You may also update the default options before calling either method:

$.alertable.defaults.optionName = yourValue;

Promises

Both alert and confirm return a promise-compatible (jQuery-deferred) object. As a result, you can use any of the supported chainable methods. However, the examples above demonstrate the most appropriate ones to use.