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

confirmmodal.js

v2.0.1

Published

Confirm Modal for javascript

Downloads

23

Readme

Build Status

ConfirmModal.js

Modern Confirm Modal javascript module for browsers, standalone instalation. No libs/frameworks (jQuery, Bootstrap, etc...) required

Install

As npm package, from Github

npm install confirmmodal.js --save

As zip file

Setup

As ES6 module

import ConfirmModal from "confirmmodal.js/lib/ConfirmModal";

As script

include the script located on the dist folder

<script src="dist/ConfirmModal.js"></script>

Now, you need to instantiate it passing some 'options', and open it

let modal = new ConfirmModal(options)
modal.open()

Options

User can provide an object with several keys:

  • messages: json with the labels (title, description, cancel and proceed buttons)
  • cssclasses: json with the css classes from the cancel and proceed buttons. If provided, will override default values
  • onProceed: function to be called after proceed, if provided
  • onCancel: function to be called after cancel, if provided
  • prompt: json with settings for user prompt (if is enabled, and if is required)

Examples:

var options = { messages: {
				title: "Título!",
				desc: "descrição longa",
				proceed: "ok",
				cancel: "cancelar"
			},
			onProceed: function() {
				console.log('ok clicked');
			},
			cssclasses: {
				btn_cancel: "btn any-class", //default is 'btn btn-danger'
				btn_proceed: "any-other-class" //default is 'btn btn-primary'
			},
			buttons: {
				cancel: false, //default is true
				proceed: false //default is true
			},
			prompt: {
				enabled: true, //default is false
				required: true //default is false 
			}
		}

onProceed callback

When onProceed callback is called, the instance of the ConfirmModal is passed as the argument to it. If prompt is enabled, the value filled by in the modal can be retrieved using the 'promptvalue' attribute, as follows:

onProceed: function(my_modal) {
	console.log(my_modal.promptvalue)
}

Close the confirm modal programmatically

modal.close()

Events

The ConfirmModal object has 2 events: proceed and cancel. Both return a promise, which are resolved when user clicks in one of the buttons.

confirm
.on('proceed')
.then( function(my_modal) {
	console.log('Resolved, button proceed licked')
})

confirm
.on('cancel')
.then( function(my_modal) {
	console.log('Resolved, button proceed licked')
})

Check the promises.html in the examples/ folder

Example

Checkout the examples/ folder for with samples TODO: online examples

Tests

Unit

Specs are under test/unit/ path

Run

npm run test-unit

Integration

Specs are under test/integration/ path. They use Webdriver.io to control a browser and automatize tests Install selenium-standalone as npm package and start it

npm install selenium-standalone@latest -g
selenium-standalone install
selenium-standalone start

Run

npm run test-integration

All definitions are set in wdio.conf.js