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

data-confirm-modal

v1.6.2

Published

Makes Rails' link_to confirm: 'foo' build a Bootstrap Modal instead of calling the browser's confirm() API.

Downloads

21,080

Readme

Data-Confirm Modal

Gem Version

Uses Bootstrap's modals in place of the browser's builtin confirm() API for links generated through Rails' helpers with the :confirm option.

Any link with the data-confirm attribute will trigger a Bootstrap modal.

HTML in the modal supported, and also the ability to have the user input a certain value, for extra willingness confirmation (inspired by GitHub's "delete repository" function).

Installation

Add this line to your application's Gemfile:

gem 'data-confirm-modal'

The library supports Bootstrap 3 and 4. If you are stuck on Bootstrap 2.3, you must use the bootstrap2 branch:

gem 'data-confirm-modal', github: 'ifad/data-confirm-modal', branch: 'bootstrap2'

Then execute:

$ bundle

And then require the Javascript from your application.js:

//= require data-confirm-modal

Usage

With Rails: example B3, example B4

By default, the Gem's Javascript overrides Rails' [data-confirm behaviour][] for you, with no change required to your code. The modal is applicable to <a>, <button> and <input[submit]> elements by default.

<%= link_to 'Delete', data: {confirm: 'Are you sure?'} %>

The modal's title text can be customized using the data-title attribute. If data-title is not defined it falls back to the title attribute.

<%= link_to 'Delete', data: {title: 'Are You Sure?'} %>

The modal's 'confirm' button text can be customized using the data-commit attribute.

<%= link_to 'Delete', data: {confirm: 'Are you sure?', commit: 'Sure!'} %>

Add a data-verify attribute to your input if you want an extra confirmation from the user. The modal will contain an extra text input, and the user will be asked to type the verification value before being allowed to proceed.

<%= link_to 'Delete', data: {confirm: 'Are you sure?', verify: 'Foo', verify_text: 'Type "Foo" to confirm'} %>

You can set global setting using dataConfirmModal.setDefaults, for example:

dataConfirmModal.setDefaults({
  title: 'Confirm your action',
  commit: 'Continue',
  cancel: 'Cancel'
});

To restore default settings use dataConfirmModal.restoreDefaults().

Without Rails, with data attributes: example B3, example B4

Given an element with data-confirm attributes in place, such as

<a id="foo" href="#" data-confirm="Really do this?" data-commit="Do it" data-cancel="Not really"/>

you can then invoke .confirmModal() on it using:

$('#foo').confirmModal();

that'll display the confirmation modal. If the user confirms, then the #foo link will receive a click event.

Without Rails, without data attributes: example B3, example B4

Use dataConfirmModal.confirm() passing any of the supported options, and pass an onConfirm and onCancel callbacks that'll be invoked when the user clicks the confirm or the cancel buttons.

dataConfirmModal.confirm({
  title: 'Are you sure?',
  text: 'Really do this?',
  commit: 'Yes do it',
  cancel: 'Not really',
  zIindex: 10099,
  onConfirm: function() { alert('confirmed') },
  onCancel:  function() { alert('cancelled') }
});

Modal Options

The default bootstrap modal options can be passed either via JavaScript or through data attributes.

 $('#foo').confirmModal({backdrop: 'static', keyboard: false});

or

 <a href="#" data-confirm="Really?" data-backdrop="static" data-keyboard="false">

Authors

Background

Spinned off a corporate IFAD application in which an user did too much damage because the confirm wasn't THAT explicit ... ;-).

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request