data-confirm-modal 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -7
- data/lib/data-confirm-modal/version.rb +1 -1
- data/package.json +1 -1
- data/vendor/assets/javascripts/data-confirm-modal.js +46 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 499d44b1254e1733f2c500c502ec93ebaeb2019c
|
4
|
+
data.tar.gz: 40188e1811123f215a49d6e9ab5b1092605e0ccb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ff311becfd5eca22ccbb8f01af4df98875e07b0aea4cedf42b7730d0d9876d68bbd947b5145958528cfac27e21529741c4b53d4196449fa41b356639cafe3f
|
7
|
+
data.tar.gz: 334261aef657e5fb3ae2b5cb4f717741541ae143403061bcd3115b765a1c323e2066c096a382c790b44609b81f89ae1f024ed70be94ed405255bef36517e039f
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/data-confirm-modal.svg)](https://badge.fury.io/rb/data-confirm-modal)
|
4
4
|
|
5
|
-
Uses [Bootstrap's modals](
|
5
|
+
Uses [Bootstrap's modals](https://twitter.github.io/bootstrap/javascript.html#modals)
|
6
6
|
in place of the browser's builtin `confirm()` API for links generated through Rails'
|
7
7
|
helpers with the `:confirm` option.
|
8
8
|
|
@@ -18,7 +18,8 @@ Add this line to your application's Gemfile:
|
|
18
18
|
|
19
19
|
gem 'data-confirm-modal'
|
20
20
|
|
21
|
-
|
21
|
+
The library supports Bootstrap 3 and 4. If you are stuck on Bootstrap 2.3, you must
|
22
|
+
use the `bootstrap2` branch:
|
22
23
|
|
23
24
|
gem 'data-confirm-modal', github: 'ifad/data-confirm-modal', branch: 'bootstrap2'
|
24
25
|
|
@@ -32,7 +33,7 @@ And then require the Javascript from your `application.js`:
|
|
32
33
|
|
33
34
|
## Usage
|
34
35
|
|
35
|
-
### With Rails
|
36
|
+
### With Rails: [example B3](https://jsfiddle.net/zpu4u6mh/), [example B4](https://jsfiddle.net/02t20nwx/)
|
36
37
|
|
37
38
|
By default, the Gem's Javascript overrides Rails' [data-confirm behaviour][]
|
38
39
|
for you, with no change required to your code. The modal is applicable to
|
@@ -68,7 +69,7 @@ To restore default settings use `dataConfirmModal.restoreDefaults()`.
|
|
68
69
|
|
69
70
|
[data-confirm-behaviour]: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html
|
70
71
|
|
71
|
-
### Without Rails, with data attributes ([example](
|
72
|
+
### Without Rails, with data attributes: [example B3](https://jsfiddle.net/nugqscyx/), [example B4](https://jsfiddle.net/0g53ar5n/)
|
72
73
|
|
73
74
|
Given an element with `data-confirm` attributes in place, such as
|
74
75
|
|
@@ -81,7 +82,7 @@ you can then invoke `.confirmModal()` on it using:
|
|
81
82
|
that'll display the confirmation modal. If the user confirms, then the `#foo`
|
82
83
|
link will receive a `click` event.
|
83
84
|
|
84
|
-
### Without Rails, without data attributes
|
85
|
+
### Without Rails, without data attributes: [example B3](https://jsfiddle.net/h370g63r/), [example B4](https://jsfiddle.net/veg879px/)
|
85
86
|
|
86
87
|
Use `dataConfirmModal.confirm()` passing any of the supported options, and pass
|
87
88
|
an `onConfirm` and `onCancel` callbacks that'll be invoked when the user clicks
|
@@ -99,7 +100,7 @@ the confirm or the cancel buttons.
|
|
99
100
|
|
100
101
|
### Modal Options
|
101
102
|
|
102
|
-
The default [bootstrap modal options](
|
103
|
+
The default [bootstrap modal options](https://getbootstrap.com/javascript/#modals-options)
|
103
104
|
can be passed either via JavaScript or through data attributes.
|
104
105
|
|
105
106
|
$('#foo').confirmModal({backdrop: 'static', keyboard: false});
|
@@ -116,7 +117,7 @@ or
|
|
116
117
|
|
117
118
|
## Background
|
118
119
|
|
119
|
-
Spinned off a corporate [IFAD](
|
120
|
+
Spinned off a corporate [IFAD](https://github.com/ifad/) application in which
|
120
121
|
an user did too much damage because the confirm wasn't *THAT* explicit ... ;-).
|
121
122
|
|
122
123
|
## Contributing
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "data-confirm-modal",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.6.0",
|
4
4
|
"description": "Makes Rails' link_to confirm: 'foo' build a Bootstrap Modal instead of calling the browser's confirm() API.",
|
5
5
|
"main": "vendor/assets/javascripts/data-confirm-modal.js",
|
6
6
|
"repository": "https://github.com/ifad/data-confirm-modal.git",
|
@@ -89,6 +89,31 @@
|
|
89
89
|
|
90
90
|
dataConfirmModal.restoreDefaults();
|
91
91
|
|
92
|
+
// Detect bootstrap version, or bail out.
|
93
|
+
//
|
94
|
+
if ($.fn.modal == undefined) {
|
95
|
+
throw new Error("The bootstrap modal plugin does not appear to be loaded.");
|
96
|
+
}
|
97
|
+
|
98
|
+
if ($.fn.modal.Constructor == undefined) {
|
99
|
+
throw new Error("The bootstrap modal plugin does not have a Constructor ?!?");
|
100
|
+
}
|
101
|
+
|
102
|
+
if ($.fn.modal.Constructor.VERSION == undefined) {
|
103
|
+
throw new Error("The bootstrap modal plugin does not have its version defined ?!?");
|
104
|
+
}
|
105
|
+
|
106
|
+
var versionString = $.fn.modal.Constructor.VERSION;
|
107
|
+
var match = versionString.match(/^(\d)\./);
|
108
|
+
if (!match) {
|
109
|
+
throw new Error("Cannot identify Bootstrap version. Version string: " + versionString);
|
110
|
+
}
|
111
|
+
|
112
|
+
var bootstrapVersion = parseInt(match[1]);
|
113
|
+
if (bootstrapVersion != 3 && bootstrapVersion != 4) {
|
114
|
+
throw new Error("Unsupported bootstrap version: " + bootstrapVersion + ". data-confirm-modal supports version 3 and 4.");
|
115
|
+
}
|
116
|
+
|
92
117
|
var buildElementModal = function (element) {
|
93
118
|
var options = {
|
94
119
|
title: element.data('title') || element.attr('title') || element.data('original-title'),
|
@@ -127,13 +152,32 @@
|
|
127
152
|
var fade = settings.fade ? 'fade' : '';
|
128
153
|
var modalClass = options.modalClass ? options.modalClass : settings.modalClass;
|
129
154
|
|
155
|
+
var modalTitle = '<h5 id="'+id+'Label" class="modal-title"></h5> '
|
156
|
+
var modalClose = '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>';
|
157
|
+
var modalHeader;
|
158
|
+
|
159
|
+
// Bootstrap 3 and 4 have different DOMs and different CSS. In B4, the
|
160
|
+
// modalHeader is display:flex and the modalClose uses negative margins,
|
161
|
+
// so it can stay after the modalTitle.
|
162
|
+
//
|
163
|
+
// In B3, the close button floats to the right, so it must stay before
|
164
|
+
// the modalTitle.
|
165
|
+
//
|
166
|
+
switch (bootstrapVersion) {
|
167
|
+
case 3:
|
168
|
+
modalHeader = modalClose + modalTitle;
|
169
|
+
break;
|
170
|
+
case 4:
|
171
|
+
modalHeader = modalTitle + modalClose;
|
172
|
+
break;
|
173
|
+
}
|
174
|
+
|
130
175
|
var modal = $(
|
131
176
|
'<div id="'+id+'" class="modal '+modalClass+' '+fade+'" tabindex="-1" role="dialog" aria-labelledby="'+id+'Label" aria-hidden="true">' +
|
132
177
|
'<div class="modal-dialog" role="document">' +
|
133
178
|
'<div class="modal-content">' +
|
134
179
|
'<div class="modal-header">' +
|
135
|
-
|
136
|
-
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
|
180
|
+
modalHeader +
|
137
181
|
'</div>' +
|
138
182
|
'<div class="modal-body"></div>' +
|
139
183
|
'<div class="modal-footer">' +
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data-confirm-modal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcello Barnaba
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: 1.3.6
|
66
66
|
requirements: []
|
67
67
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.
|
68
|
+
rubygems_version: 2.5.2.1
|
69
69
|
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: Use bootstrap modals with Rails' UJS data-confirm
|