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

bootstrap-popups

v1.0.1

Published

bootstrap dialog popups

Downloads

20

Readme

Bootstrap Popups

This is a simple popup library based on Bootstrap Modal component, which can be used to replace the default window confirm and alert dialog boxes.

Install

npm install bootstrap-popups --save

Usage

This library is dependent on JQuery and Bootstrap JS, which are defined as external dependencies. You don't need to bother import them explicitly. Just run "npm install" and they will be ready for use.

However you need to include bootstrap CSS in your app to make sure styles are correctly applied.

import "bootstrap/dist/css/bootstrap.min.css";
import popups from "bootstrap-popups";

Confirm Box

import $ from "jquery";

// Click "Yes" button to confirm. The box will close immediately.
$("#btn-confirm").click(() => {
  popups.confirm({
    message: "Are you sure to do this?",
    task: doSomething,
  });
});

function doSomething() {
  console.log("Done");
}

The dialog box will close immediately after "Yes" button is clicked, and the task will be executed asynchronously.

Config Arguments

The "confirm" function accepts a config which has the following attributes.

| Attribute | Description | Type | | :-----------: | --------------------------------------------- | :--------: | | message | Confirm message to show in the box. | string | | task | Task to execute when "Yes" button is clicked. | function | | syncWait | If set true, the confirm box will wait for the task to finish,and show an animated progress bar. | bool |

Sync Wait Mode

Sometimes you may want the dialog box to wait for the task to finish, e.g. waiting for an AJAX response. To enable this feature, you can use the "syncWait" mode. In this mode, the task must be a promisable which takes arguments (resolve, reject), and call resolve/reject respectively inside the task.

// Confirm and sync wait the task to be done.
$("#btn-confirm2").click(() => {
  popups.confirm({
    message: "Are you sure to do this?",
    task: doSomethingWait,
    syncWait: true,
  });
});

function doSomethingWait(resolve, reject) {
  setTimeout(() => {
    console.log("Done");
    resolve();
    // reject("Failed: remote server error.");
  }, 1000);
}

After "Yes" button is clicked, the box will show a fake prgoress bar, and disappears after task is done:

Note your task must call resolve/reject, otherwise the dialog box and progress bar will never close. If reject is called with some error message, the dialog box will finally display this message.

Alert Box

Alert is simple. It just takes a warning message to show in the box.

$("#btn-alert").click(() => {
  popups.alert("You can NOT do this! It is very dangerous operation.");
});

Use in browser

This library is built as UMD compliant. So it can also be loaded directly in browser either by <script> or AMD, with module
name "popups". Note when used in this way, you need to load JQuery and Bootstrap JS/CSS before this module.

License

MIT License