data_confirm_modal 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4377cbbdb26816736adcb6f1fc3539cc526d61ad
|
4
|
+
data.tar.gz: 2198698d92a7a90e8f0085aa461e33a47a3851d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44ac32d2a689d9cc429fe48a61d81b85f9d5701d72a96b8e5fed6c1e7a07b3d9589610bcdd45bbb39614bd6dee34769be84781e12b53b07f675ede11ea422c21
|
7
|
+
data.tar.gz: bf2bc439c60d2254e1b1a3b304186e0d740276bdec62da4a8aa7f0d3eda3d25a13bb33125210dee1a8503c20a735531068257d2e24716aad119741b753a1f95a
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# DataConfirmModal
|
2
2
|
|
3
|
-
|
3
|
+
This Gem was designed as a simple solution to integrate https://github.com/agoragames/confirm-with-reveal into your rails 4+ Application. I have added some instructions on how to customize the modals below, however for full documentation on the original plugin please refer to the repo above.
|
4
4
|
|
5
|
-
|
5
|
+
Please note this gem is still in development, and will change continuously, please follow this page to keep current with updates.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -21,16 +21,40 @@ Or install it yourself as:
|
|
21
21
|
$ gem install data_confirm_modal
|
22
22
|
|
23
23
|
## Usage
|
24
|
-
This Gem is only compatible with Foundation Framework 5+
|
24
|
+
### At Present This Gem is only compatible with Foundation Framework 5+
|
25
25
|
|
26
|
-
|
27
|
-
Troubleshoot integration
|
26
|
+
Add to your application.js like shown below:
|
28
27
|
|
29
|
-
|
28
|
+
```ruby
|
29
|
+
//= require jquery_ujs
|
30
|
+
//= require foundation
|
31
|
+
//= require data_confirm_modal
|
32
|
+
```
|
33
|
+
|
34
|
+
Add the following to the bottom of the page but above ```</html>``` that contains the modal you wish to modify:
|
35
|
+
|
36
|
+
With out forcing a user to type a "Password (that you define)" to continue
|
37
|
+
```ruby
|
38
|
+
<script>
|
39
|
+
$(document).confirmWithReveal({
|
40
|
+
ok: 'Proceed',
|
41
|
+
cancel: 'Cancel'
|
42
|
+
})
|
43
|
+
</script>
|
44
|
+
```
|
30
45
|
|
31
|
-
|
46
|
+
To force a user to type a password of your choosing to proceed with the action:
|
32
47
|
|
33
|
-
|
48
|
+
```ruby
|
49
|
+
<script>
|
50
|
+
$(document).confirmWithReveal({
|
51
|
+
password: 'DELETE'
|
52
|
+
ok: 'Proceed',
|
53
|
+
cancel: 'Cancel'
|
54
|
+
})
|
55
|
+
</script>
|
56
|
+
```
|
57
|
+
To Be Continued... This should be enough to get you out of the gate!
|
34
58
|
|
35
59
|
## Contributing
|
36
60
|
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# Examples using Rails’ link_to helper
|
2
|
+
#
|
3
|
+
# Basic usage:
|
4
|
+
# = link_to 'Delete', foo_path(foo), method: :delete, data: { confirm: true }
|
5
|
+
#
|
6
|
+
# Customization of individual links/buttons via JSON in data-confirm:
|
7
|
+
# = link_to 'Delete', foo_path(foo), method: :delete, data: {
|
8
|
+
# confirm: {
|
9
|
+
# title: 'You might want to think twice about this!',
|
10
|
+
# body: 'If you click “Simon Says Delete” there will be no takebacks!',
|
11
|
+
# ok: 'Simon Says Delete'
|
12
|
+
# }
|
13
|
+
# }
|
14
|
+
#
|
15
|
+
# Fall back to window.confirm() when confirm is a plain string:
|
16
|
+
# = link_to 'Delete', foo_path(foo), method: :delete, confirm: 'Are you sure?'
|
17
|
+
|
18
|
+
$ = this.jQuery
|
19
|
+
|
20
|
+
$.fn.extend
|
21
|
+
confirmWithReveal: (options = {}) ->
|
22
|
+
|
23
|
+
defaults =
|
24
|
+
modal_class: 'medium'
|
25
|
+
title: 'Are you sure?'
|
26
|
+
title_class: ''
|
27
|
+
body: 'This action cannot be undone.'
|
28
|
+
body_class: ''
|
29
|
+
password: false
|
30
|
+
prompt: 'Type <strong>%s</strong> to continue:'
|
31
|
+
footer_class: ''
|
32
|
+
ok: 'Confirm'
|
33
|
+
ok_class: 'button alert'
|
34
|
+
cancel: 'Cancel'
|
35
|
+
cancel_class: 'button secondary'
|
36
|
+
|
37
|
+
settings = $.extend {}, defaults, options
|
38
|
+
|
39
|
+
do_confirm = ($el) ->
|
40
|
+
|
41
|
+
el_options = $el.data('confirm')
|
42
|
+
|
43
|
+
# The confirmation is actually triggered again when hitting "OK"
|
44
|
+
# (or whatever) in the modal (since we clone the original link in),
|
45
|
+
# but since we strip off the 'confirm' data attribute, we can tell
|
46
|
+
# whether this is the first confirmation or a subsequent one.
|
47
|
+
return true unless $el.attr('data-confirm')?
|
48
|
+
|
49
|
+
if (typeof el_options == 'string') and (el_options.length > 0)
|
50
|
+
return ($.rails?.confirm || window.confirm).call(window, el_options)
|
51
|
+
|
52
|
+
option = (name) ->
|
53
|
+
el_options[name] || settings[name]
|
54
|
+
|
55
|
+
# TODO: allow caller to pass in a template (DOM element to clone?)
|
56
|
+
modal = $("""
|
57
|
+
<div data-reveal class='reveal-modal #{option 'modal_class'}'>
|
58
|
+
<h2 data-confirm-title class='#{option 'title_class'}'></h2>
|
59
|
+
<p data-confirm-body class='#{option 'body_class'}'></p>
|
60
|
+
<div data-confirm-footer class='#{option 'footer_class'}'>
|
61
|
+
<a data-confirm-cancel class='#{option 'cancel_class'}'></a>
|
62
|
+
</div>
|
63
|
+
</div>
|
64
|
+
""")
|
65
|
+
|
66
|
+
confirm_button = if $el.is('a') then $el.clone() else $('<a/>')
|
67
|
+
confirm_button
|
68
|
+
.removeAttr('data-confirm')
|
69
|
+
.attr('class', option 'ok_class')
|
70
|
+
.html(option 'ok')
|
71
|
+
.on 'click', (e) ->
|
72
|
+
return false if $(this).prop('disabled')
|
73
|
+
# TODO: Handlers of this event cannot stop the confirmation from
|
74
|
+
# going through (e.g. chaining additional validation). Fix TBD.
|
75
|
+
$el.trigger('confirm.reveal', e)
|
76
|
+
if $el.is('form, :input')
|
77
|
+
$el
|
78
|
+
.closest('form')
|
79
|
+
.removeAttr('data-confirm')
|
80
|
+
.submit()
|
81
|
+
|
82
|
+
modal
|
83
|
+
.find('[data-confirm-title]')
|
84
|
+
.html(option 'title')
|
85
|
+
modal
|
86
|
+
.find('[data-confirm-body]')
|
87
|
+
.html(option 'body')
|
88
|
+
modal
|
89
|
+
.find('[data-confirm-cancel]')
|
90
|
+
.html(option 'cancel')
|
91
|
+
.on 'click', (e) ->
|
92
|
+
modal.foundation('reveal', 'close')
|
93
|
+
$el.trigger('cancel.reveal', e)
|
94
|
+
modal
|
95
|
+
.find('[data-confirm-footer]')
|
96
|
+
.append(confirm_button)
|
97
|
+
|
98
|
+
if (password = option 'password')
|
99
|
+
confirm_label =
|
100
|
+
(option 'prompt')
|
101
|
+
.replace '%s', password
|
102
|
+
confirm_html = """
|
103
|
+
<label>
|
104
|
+
#{confirm_label}
|
105
|
+
<input data-confirm-password type='text'/>
|
106
|
+
</label>
|
107
|
+
"""
|
108
|
+
modal
|
109
|
+
.find('[data-confirm-body]')
|
110
|
+
.after($(confirm_html))
|
111
|
+
modal
|
112
|
+
.find('[data-confirm-password]')
|
113
|
+
.on 'keyup', (e) ->
|
114
|
+
disabled = $(this).val() != password
|
115
|
+
confirm_button
|
116
|
+
.toggleClass('disabled', disabled)
|
117
|
+
.prop('disabled', disabled)
|
118
|
+
.trigger('keyup')
|
119
|
+
|
120
|
+
modal
|
121
|
+
.appendTo($('body'))
|
122
|
+
.foundation()
|
123
|
+
.foundation('reveal', 'open')
|
124
|
+
.on 'closed.fndtn.reveal', (e) ->
|
125
|
+
modal.remove()
|
126
|
+
|
127
|
+
return false
|
128
|
+
|
129
|
+
if $.rails
|
130
|
+
|
131
|
+
# We do NOT do the event binding if $.rails exists, because jquery_ujs
|
132
|
+
# has already done it for us
|
133
|
+
|
134
|
+
$.rails.allowAction = (link) -> do_confirm $(link)
|
135
|
+
return $(this)
|
136
|
+
|
137
|
+
else
|
138
|
+
|
139
|
+
handler = (e) ->
|
140
|
+
unless (do_confirm $(this))
|
141
|
+
e.preventDefault()
|
142
|
+
e.stopImmediatePropagation()
|
143
|
+
|
144
|
+
return @each () ->
|
145
|
+
$el = $(this)
|
146
|
+
$el.on 'click', 'a[data-confirm], :input[data-confirm]', handler
|
147
|
+
$el.on 'submit', 'form[data-confirm]', handler
|
148
|
+
$el
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_confirm_modal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Wilson
|
@@ -57,7 +57,8 @@ files:
|
|
57
57
|
- data_confirm_modal.gemspec
|
58
58
|
- lib/data_confirm_modal.rb
|
59
59
|
- lib/data_confirm_modal/version.rb
|
60
|
-
- vendor/assets/javascripts/
|
60
|
+
- vendor/assets/javascripts/data-confirm-modal.coffee
|
61
|
+
- vendor/assets/javascripts/data-confirm-modal.js
|
61
62
|
homepage: https://github.com/swilson223/data-confirm-foundation
|
62
63
|
licenses:
|
63
64
|
- MIT
|