data-confirm-modal 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -5
- data/data-confirm-modal.gemspec +0 -1
- data/lib/data-confirm-modal/version.rb +1 -1
- data/vendor/assets/javascripts/data-confirm-modal.js +40 -20
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 036d8ef59a741d41fdde8be51c5133108deda949
|
4
|
+
data.tar.gz: 78e832d68393925aeff5e1643159dc338b76c615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 252e3c3a9d9fd2eb9c5a450ae7d3cc100f3ddb6a50778e1a75a45583a48dba3eebf29c49c4781fdd0db1a4983e3e6fb095569a4b14d73e8a28743b846ef41442
|
7
|
+
data.tar.gz: 27e3cddc2965780e9a74a216b6510e75008f14c42e60407a2d799e45f2dc6025a6a92ece54fb0a5cad70c6bc7d6620cafda18faf996c1d3b3f39089b37a6f871
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ And then require the Javascript from your `application.js`:
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
-
### With Rails
|
33
|
+
### With Rails ([example](http://jsfiddle.net/zpu4u6mh/))
|
34
34
|
|
35
35
|
By default, the Gem's Javascript overrides Rails' [data-confirm behaviour][]
|
36
36
|
for you, with no change required to your code. The modal is applicable to
|
@@ -67,7 +67,7 @@ To restore default settings use `dataConfirmModal.restoreDefaults()`.
|
|
67
67
|
|
68
68
|
[data-confirm-behaviour]: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html
|
69
69
|
|
70
|
-
### Without Rails, with data attributes
|
70
|
+
### Without Rails, with data attributes ([example](http://jsfiddle.net/ze2Lz8tm/))
|
71
71
|
|
72
72
|
Given an element with `data-confirm` attributes in place, such as
|
73
73
|
|
@@ -80,7 +80,7 @@ you can then invoke `.confirmModal()` on it using:
|
|
80
80
|
that'll display the confirmation modal. If the user confirms, then the `#foo`
|
81
81
|
link will receive a `click` event.
|
82
82
|
|
83
|
-
### Without Rails, without data attributes
|
83
|
+
### Without Rails, without data attributes ([example](https://jsfiddle.net/h370g63r/))
|
84
84
|
|
85
85
|
Use `dataConfirmModal.confirm()` passing any of the supported options, and pass
|
86
86
|
an `onConfirm` and `onCancel` callbacks that'll be invoked when the user clicks
|
@@ -96,8 +96,6 @@ the confirm or the cancel buttons.
|
|
96
96
|
onCancel: function() { alert('cancelled') }
|
97
97
|
});
|
98
98
|
|
99
|
-
A live jsfiddle example is [available here](http://jsfiddle.net/t0m7ayr3/).
|
100
|
-
|
101
99
|
### Modal Options
|
102
100
|
|
103
101
|
The default [bootstrap modal options](http://getbootstrap.com/javascript/#modals-options)
|
data/data-confirm-modal.gemspec
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "http://github.com/ifad/data-confirm-modal"
|
11
11
|
s.summary = "Use bootstrap modals with Rails' UJS data-confirm"
|
12
12
|
s.description = "This gem overrides Rails' UJS behaviour to open up a Bootstrap Modal instead of the browser's built in confirm() dialog"
|
13
|
-
s.licenses = "MIT"
|
14
13
|
|
15
14
|
s.required_rubygems_version = ">= 1.3.6"
|
16
15
|
|
@@ -111,10 +111,10 @@
|
|
111
111
|
|
112
112
|
var modal = buildModal(options);
|
113
113
|
|
114
|
-
modal.data('confirmed', false);
|
115
114
|
modal.find('.commit').on('click', function () {
|
116
|
-
|
117
|
-
element.
|
115
|
+
// Call the original event handler chain
|
116
|
+
element.get(0).click();
|
117
|
+
|
118
118
|
modal.modal('hide');
|
119
119
|
});
|
120
120
|
|
@@ -239,43 +239,63 @@
|
|
239
239
|
* caching it into the element's `confirm-modal` data attribute.
|
240
240
|
*/
|
241
241
|
var getModal = function (element) {
|
242
|
-
var modal = element.data('confirm-modal')
|
242
|
+
var modal = element.data('confirm-modal');
|
243
243
|
|
244
|
-
if (
|
244
|
+
if (!modal) {
|
245
|
+
modal = buildElementModal(element);
|
245
246
|
element.data('confirm-modal', modal);
|
247
|
+
}
|
246
248
|
|
247
249
|
return modal;
|
248
250
|
};
|
249
251
|
|
250
252
|
$.fn.confirmModal = function () {
|
251
|
-
getModal($(this))
|
253
|
+
var modal = getModal($(this));
|
254
|
+
|
255
|
+
modal.spawn();
|
252
256
|
|
253
|
-
return
|
257
|
+
return modal;
|
254
258
|
};
|
255
259
|
|
256
260
|
if ($.rails) {
|
257
261
|
/**
|
258
|
-
* Attaches to
|
259
|
-
* `data-confirm` attribute
|
260
|
-
*
|
261
|
-
* the modal
|
262
|
+
* Attaches to Rails' UJS adapter's 'confirm' event, triggered on elements
|
263
|
+
* having a `data-confirm` attribute set.
|
264
|
+
*
|
265
|
+
* If the modal is not visible, then it is spawned and the default Rails
|
266
|
+
* confirmation dialog is canceled.
|
267
|
+
*
|
268
|
+
* If the modal is visible, it means the handler is being called by the
|
269
|
+
* modal commit button click handler, as such the user has successfully
|
270
|
+
* clicked on the confirm button. In this case Rails' confirm function
|
271
|
+
* is briefly overriden, and afterwards reset when the modal is closed.
|
262
272
|
*
|
263
|
-
* A modal is considered 'confirmed' when an user has successfully clicked
|
264
|
-
* the 'confirm' button in it.
|
265
273
|
*/
|
274
|
+
var rails_confirm = $.rails.confirm;
|
275
|
+
|
266
276
|
$(document).delegate(settings.elements.join(', '), 'confirm', function() {
|
267
277
|
var element = $(this), modal = getModal(element);
|
268
|
-
var confirmed = modal.data('confirmed');
|
269
278
|
|
270
|
-
if (!
|
279
|
+
if (!modal.is(':visible')) {
|
271
280
|
modal.spawn();
|
272
281
|
|
273
|
-
|
274
|
-
|
275
|
-
modal.on('hide', function () { $.rails.confirm = confirm; });
|
276
|
-
}
|
282
|
+
// Cancel Rails' confirmation
|
283
|
+
return false;
|
277
284
|
|
278
|
-
|
285
|
+
} else {
|
286
|
+
// Modal has been confirmed. Override Rails' handler
|
287
|
+
$.rails.confirm = function () {
|
288
|
+
return true;
|
289
|
+
}
|
290
|
+
|
291
|
+
modal.one('hidden.bs.modal', function() {
|
292
|
+
// Reset it after modal is closed.
|
293
|
+
$.rails.confirm = rails_confirm;
|
294
|
+
});
|
295
|
+
|
296
|
+
// Proceed with Rails' handlers
|
297
|
+
return true;
|
298
|
+
}
|
279
299
|
});
|
280
300
|
}
|
281
301
|
|
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.2.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: 2016-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -43,8 +43,7 @@ files:
|
|
43
43
|
- lib/data-confirm-modal/version.rb
|
44
44
|
- vendor/assets/javascripts/data-confirm-modal.js
|
45
45
|
homepage: http://github.com/ifad/data-confirm-modal
|
46
|
-
licenses:
|
47
|
-
- MIT
|
46
|
+
licenses: []
|
48
47
|
metadata: {}
|
49
48
|
post_install_message:
|
50
49
|
rdoc_options: []
|
@@ -62,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
61
|
version: 1.3.6
|
63
62
|
requirements: []
|
64
63
|
rubyforge_project:
|
65
|
-
rubygems_version: 2.
|
64
|
+
rubygems_version: 2.4.8
|
66
65
|
signing_key:
|
67
66
|
specification_version: 4
|
68
67
|
summary: Use bootstrap modals with Rails' UJS data-confirm
|