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

nudge-js

v1.0.6-2

Published

Thin replacement for JavaScript's alert().

Downloads

5

Readme

Introductions

Nudge is a very light replacement for JavaScript's alert() based on the excellent Featherlight jQuery lightbox plugin.

It is simple, uses sensible css (everything is name-spaced using BEM conventions), it's completely customizable and the girls love it!

Installation

Nudge requires jQuery and Featherlight.

As soon you've got those down, you can manually grab the latest release or install using bower:

bower install giant-nudge

You should then make sure to include the scripts below:

  • dist/nudge.min.js (its majesty)
  • dist/nudge.min.css (basic overlays and centering)

and maybe also include the most absolutely minimal theme from:

  • dist/themes/lite.min.css

If you're a Sassy person, you might find src/nudge.scss and src/nudge-lite.scss handy. Just saying.

Usage

You can create (and store) Nudges by instantiating the globally exposed class Nudge:

var myNudge = new Nudge(options);

You can then show them, optionally overriding some (or all) of the options:

myNudge.give(options);

You can even create and show Nudges on-the-fly:

Nudge.give(options);

Options

Whether you're creating a new instance, showing an instance or showing a Nudge on-the-fly, you can define the options you need to set in the form of a JavaScript object.

title String default: ''
The title to display.

message String default: ''
The message to display.

confirmText String default: 'OK'
Confirmation button text.

showCancel Boolean default: false
Whether to show a cancel button.

cancelText String default: 'Cancel'
Cancel button text.

prompt Boolean default: false
Wether to show an input prompt. When set to true, a text input field will be shown after the message.

promptDefault String default: ''
Default text for the prompt input field.

namespace String default: 'nudge-message'
Message container class and elements prefix.

variant String default: null
Message container class modifier.

For example: if your namespace is alert and you pass in the variant success, the class alert--success will be added to the message container.

onConfirm Function
A callback to execute when the confirm button is clicked. this is the Nudge instance. The current Featherlight instance is passed as a parameter to the callback.

This is what the default callback that closes the modal looks like:

function(featherlight) {
    featherlight.close()
};

onCancel Function
A callback to execute when the cancel button is clicked. this is the Nudge instance. The current Featherlight instance is passed as a parameter to the callback.

This is what the default callback that closes the modal looks like:

function(featherlight) {
    featherlight.close()
};

onInput Function default: $.noop()
A callback to execute right before onConfirm when a prompt is displayed. this is the Nudge instance. The value entered in the input field is passed as a parameter to the callback.

modal Object
A JavaScript object that is passed directly to Featherlight when creating the modal.

By default, the following options are set:

{
    namespace: 'nudge',  /* Set our own namespace. */
    closeOnClick: false, /* Don't close the modal on click. */
    closeIcon: null      /* Don't render a close icon. */
}

Methods

give(String|Object options)
Show a Nudge using the supplied options.

  • When the parameter passed is a string, it is used to override the current message option, keeping the other settings intact.
  • When the parameter passed is an object, it is used to extend the current settings object.

Examples

If you haven't gotten the picture already, here are some examples to get you started.

// Create a Nudge.
var success = new Nudge({
    title:   'A Grand Success!',
    message: 'Everything worked out OK.',
    variant: 'success'
});

// Show the Nudge overriding the message.
success.give('That feels good.');

// Show the Nudge overriding the title as well.
success.give({
    title:   'Hot Damn!',
    message: 'That feels good.'
});	

// Create and show the same Nudge on-the-fly.
Nudge.give({
    title:   'Hot Damn!',
    message: 'That feels good.',
    variant: 'success'
});