rails-sweetalert2-confirm 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +17 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +222 -0
- data/Rakefile +12 -0
- data/lib/assets/javascripts/rails_sweetalert2_confirm.js +163 -0
- data/lib/rails_sweetalert2_confirm.rb +7 -0
- data/lib/rails_sweetalert2_confirm/rails/engine.rb +6 -0
- data/lib/rails_sweetalert2_confirm/railtie.rb +8 -0
- data/lib/rails_sweetalert2_confirm/version.rb +3 -0
- data/lib/rails_sweetalert2_confirm/view_helpers.rb +50 -0
- data/rails_sweetalert2_confirm.gemspec +29 -0
- data/spec/dummy/.gitignore +2 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/javascripts/application_turbolinks.js +17 -0
- data/spec/dummy/app/assets/stylesheets/application.css +3 -0
- data/spec/dummy/app/controllers/application_controller.rb +19 -0
- data/spec/dummy/app/views/application/destroy.html.erb +1 -0
- data/spec/dummy/app/views/application/destroy.js.erb +1 -0
- data/spec/dummy/app/views/application/index.html.erb +42 -0
- data/spec/dummy/app/views/layouts/application.html.erb +19 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +43 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/features/rails_sweetalert2_confirm_spec.rb +109 -0
- data/spec/spec_helper.rb +48 -0
- data/tags +20 -0
- metadata +241 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b17024ae196406be2bbc291db4c4680844c9034a
|
4
|
+
data.tar.gz: e44ec7a426ef55df14e471d8cb7a7d4f20be779e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 662303f02449318d6162f36464806972758eeaf37ddaac85e644ba69af4674c747b0a41f1a71743a26bcf5b8db7ea9c5a79e71406c37c4cda81a4951313095dd
|
7
|
+
data.tar.gz: 2835717b2667acda29680fca4d411a329a0daafbb250df213dcad3f44b6f41deb211f90ecf2edbbb0984a16764e2c93628882d70b0ec2728b986bd3103a1b1e6
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
env:
|
2
|
+
- RAILS_VERSION=4.0.8
|
3
|
+
- RAILS_VERSION=4.1.4
|
4
|
+
- RAILS_VERSION=4.1.4 USE_TURBOLINKS=true
|
5
|
+
- RAILS_VERSION=4.2.4
|
6
|
+
- RAILS_VERSION=4.2.4 USE_TURBOLINKS=true
|
7
|
+
- RAILS_VERSION=master
|
8
|
+
|
9
|
+
rvm:
|
10
|
+
- 1.9.3
|
11
|
+
- 2.2
|
12
|
+
- jruby-19mode
|
13
|
+
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- env: "RAILS_VERSION=master"
|
17
|
+
- rvm: ruby-head
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
Rails SweetAlert2 Confirmations <img src="https://travis-ci.org/JoeWoodward/rails-sweetalert2-confirm.svg" alt="build:">
|
2
|
+
---
|
3
|
+
|
4
|
+
An awesome [SweetAlert2](https://github.com/limonte/sweetalert2)
|
5
|
+
replacement for Rails' confirmation dialogs.
|
6
|
+
|
7
|
+
[See SweetAlert2 in action!](https://limonte.github.io/sweetalert2/)
|
8
|
+
|
9
|
+
<img src="https://raw.github.com/limonte/sweetalert2/master/sweetalert2.gif" width="686">
|
10
|
+
|
11
|
+
Installation
|
12
|
+
---
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
# Gemfile
|
16
|
+
|
17
|
+
gem 'rails-sweetalert2-confirm'
|
18
|
+
gem 'rails-assets-sweetalert2', source 'https://rails-assets.org'
|
19
|
+
```
|
20
|
+
|
21
|
+
```javascript
|
22
|
+
// app/assets/javascripts/application.js
|
23
|
+
|
24
|
+
//= require sweetalert2
|
25
|
+
//= require sweetalert2-rails-confirm
|
26
|
+
```
|
27
|
+
|
28
|
+
```css
|
29
|
+
/* app/assets/stylesheets/application.css
|
30
|
+
|
31
|
+
*= require sweetalert2
|
32
|
+
*/
|
33
|
+
```
|
34
|
+
|
35
|
+
Requirements
|
36
|
+
---
|
37
|
+
|
38
|
+
**Rails 4+**
|
39
|
+
|
40
|
+
Previous versions may be supported but are untested, use at your own risk!
|
41
|
+
|
42
|
+
Usage
|
43
|
+
---
|
44
|
+
|
45
|
+
**Basic Setup**
|
46
|
+
___
|
47
|
+
Simply implement the `link_to` with a `data: { confirm: 'message' }` as you normally would
|
48
|
+
```ruby
|
49
|
+
link_to('Another page', another_page_path, data: { confirm: 'Are you sure you want to leave this page?' })
|
50
|
+
```
|
51
|
+
|
52
|
+
**Remote Setup**
|
53
|
+
___
|
54
|
+
Simply implement the `link_to` with a `data: { confirm: 'message' }` and `remote: true` as you normally would
|
55
|
+
```ruby
|
56
|
+
link_to('Another page', another_page_path, remote: true, data: { confirm: 'Are you sure you want to leave this page?' })
|
57
|
+
```
|
58
|
+
|
59
|
+
**Setting Default SweetAlert2 Options**
|
60
|
+
___
|
61
|
+
You can define the default sweet alert options globally by creating a js
|
62
|
+
object named `sweetAlertConfirmDefaults`.
|
63
|
+
|
64
|
+
```javascript
|
65
|
+
var sweetAlertConfirmDefaults = {
|
66
|
+
title: 'Are you sure?',
|
67
|
+
type: 'warning',
|
68
|
+
showCancelButton: true,
|
69
|
+
confirmButtonText: "I'm sure"
|
70
|
+
confirmButtonClass: 'btn btn-danger'
|
71
|
+
cancelButtonClass: 'btn btn-default',
|
72
|
+
};
|
73
|
+
```
|
74
|
+
| Argument | Default value | Description |
|
75
|
+
| --------------------- | -------------------- | ----------- |
|
76
|
+
| `sweetSelector` | `"[data-swal]"` | The selector that railsSweetAlert2Confirm will look for to hijack the confirms. **This needs to be set before you import rails_sweetalert2_confirm.js** |
|
77
|
+
| `remote` | `false` | Submit the link_to or form via rails' default remote implementation |
|
78
|
+
| `afterComfirm` | N/A | Define a function to run after the user clicks the confirm button |
|
79
|
+
| `afterDismiss` | N/A | Define a function to run after the user dismisses the modal. Passes dismiss `function(dismiss)` in as a param, value of **dismiss** can be `'cancel'`, `'overlay'`, `'close'`, `'timer'` |
|
80
|
+
| `title` | N/A | The title of the modal. It can either be added to the object under the key "title" or passed as the first parameter of the function. |
|
81
|
+
| `text` | N/A | A description for the modal. It can either be added to the object under the key "text" or passed as the second parameter of the function. |
|
82
|
+
| `html` | N/A | A HTML description for the modal. If `text` and `html` parameters are provided in the same time, "text" will be used. |
|
83
|
+
| `type ` | N/A | The type of the modal. SweetAlert2 comes with [5 built-in types](#modal-types) which will show a corresponding icon animation: `warning`, `error`, `success`, `info` and `question`. It can either be put in the array under the key `type` or passed as the third parameter of the function. |
|
84
|
+
| `customClass` | N/A | A custom CSS class for the modal. |
|
85
|
+
| `animation` | `true` | If set to `false`, modal CSS animation will be disabled. |
|
86
|
+
| `allowOutsideClick` | `true` | If set to `false`, the user can't dismiss the modal by clicking outside it. |
|
87
|
+
| `allowEscapeKey` | `true` | If set to `false`, the user can't dismiss the modal by pressing the Escape key. |
|
88
|
+
| `showConfirmButton` | `true` | If set to `false`, a "Confirm"-button will not be shown. It can be useful when you're using `html` parameter for custom HTML description. |
|
89
|
+
| `showCancelButton` | `false` | If set to `true`, a "Cancel"-button will be shown, which the user can click on to dismiss the modal. |
|
90
|
+
| `confirmButtonText` | `"OK"` | Use this to change the text on the "Confirm"-button. |
|
91
|
+
| `cancelButtonText` | `"Cancel"` | Use this to change the text on the "Cancel"-button. |
|
92
|
+
| `confirmButtonColor` | `"#3085d6"` | Use this to change the background color of the "Confirm"-button (must be a HEX value). |
|
93
|
+
| `cancelButtonColor` | `"#aaa"` | Use this to change the background color of the "Cancel"-button (must be a HEX value). |
|
94
|
+
| `confirmButtonClass` | N/A | A custom CSS class for the "Confirm"-button. |
|
95
|
+
| `cancelButtonClass` | N/A | A custom CSS class for the "Cancel"-button. |
|
96
|
+
| `buttonsStyling` | `true` | Apply default swal2 styling to buttons. If you want to use your own classes (e.g. Bootstrap classes) set this parameter to `false`. |
|
97
|
+
| `reverseButtons` | `false` | Set to `true` if you want to invert default buttons positions. |
|
98
|
+
| `showCloseButton` | `false` | Set to `true` to show close button in top right corner of the modal. |
|
99
|
+
| `showLoaderOnConfirm` | `false` | Set to `true` to disable buttons and show that something is loading. Useful for AJAX requests. |
|
100
|
+
| `preConfirm` | N/A | Function to execute before confirm, should return Promise, see <a href="https://limonte.github.io/sweetalert2/#ajax-request">usage example</a>. |
|
101
|
+
| `imageUrl` | N/A | Add a customized icon for the modal. Should contain a string with the path or URL to the image. |
|
102
|
+
| `imageWidth` | N/A | If imageUrl is set, you can specify imageWidth to describes image width in px. |
|
103
|
+
| `imageHeight` | N/A | Custom image height in px. |
|
104
|
+
| `imageClass` | N/A | A custom CSS class for the customized icon. |
|
105
|
+
| `timer` | N/A | Auto close timer of the modal. Set in ms (milliseconds). |
|
106
|
+
| `width` | `500` | Modal window width, including paddings (`box-sizing: border-box`). |
|
107
|
+
| `padding` | `20` | Modal window padding. |
|
108
|
+
| `background` | `"#fff"` | Modal window background (CSS `background` property). |
|
109
|
+
| `input` | N/A | Input field type, can be `"text"`, `"email"`, `"password"`, `"textarea"`, `"select"`, `"radio"`, `"checkbox"` and `"file"`. |
|
110
|
+
| `inputPlaceholder` | N/A | Input field placeholder. |
|
111
|
+
| `inputValue` | N/A | Input field initial value. |
|
112
|
+
| `inputOptions` | N/A | If `input` parameter is set to `"select"` or `"radio"`, you can provide options. Object keys will represent options values, object values will represent options text values. |
|
113
|
+
| `inputAutoTrim` | `true` | Automatically remove whitespaces from both ends of a result string. Set this parameter to `false` to disable auto-trimming. |
|
114
|
+
| `inputValidator` | N/A | Validator for input field, should return Promise, see <a href="https://limonte.github.io/sweetalert2/#select-box">usage example</a>. |
|
115
|
+
| `inputClass` | N/A | A custom CSS class for the input field. |
|
116
|
+
| `onOpen` | N/A | Function to run when modal opens, provides modal DOM element as first param. |
|
117
|
+
| `onClose` | N/A | Function to run when modal closes, provides modal DOM element as first param. |
|
118
|
+
**N/A** means that the value isn't submitted unless defined
|
119
|
+
|
120
|
+
Please refer to the [SweetAlert2 Documentation](https://limonte.github.io/sweetalert2/) for the correct values
|
121
|
+
|
122
|
+
**NOTE**: If you would like to assign a different sweetSelector then
|
123
|
+
please create the **sweetAlertConfirmDefaults** object **before** you import
|
124
|
+
**rails_sweetalert2_confirm.js**
|
125
|
+
```javascript
|
126
|
+
// rails_sweetalert2_confirm_defaults.js
|
127
|
+
var sweetAlertConfirmDefaults = {
|
128
|
+
sweetSelector: ".sweetalert2_confirm"
|
129
|
+
}
|
130
|
+
|
131
|
+
// application.js
|
132
|
+
//= require sweetalert2
|
133
|
+
//= require rails_sweetalert2_confirm_defaults
|
134
|
+
//= require rails_sweetalert2_confirm
|
135
|
+
```
|
136
|
+
**Setting SweetAlert2 Options Per Link**
|
137
|
+
___
|
138
|
+
You can define the default sweet alert options per link_to (or
|
139
|
+
submit/button tag) by defining them on data: { swal: {} } as a json
|
140
|
+
object.
|
141
|
+
**These will override the default options**
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
link_to(
|
145
|
+
'Custom page',
|
146
|
+
custom_page_path,
|
147
|
+
data: {
|
148
|
+
confirm: 'Is this what you want?',
|
149
|
+
swal: {
|
150
|
+
text: "I'm a subtitle",
|
151
|
+
type: 'question',
|
152
|
+
confirm_button_class: 'btn btn-default'
|
153
|
+
}
|
154
|
+
}
|
155
|
+
)
|
156
|
+
```
|
157
|
+
| Argument | Default value | Description |
|
158
|
+
| --------------------- | -------------------- | ----------- |
|
159
|
+
| `remote` | `false` | Submit the link_to or form via rails' default remote implementation |
|
160
|
+
| `after_comfirm` | N/A | Define a function to run after the user clicks the confirm button |
|
161
|
+
| `after_dismiss` | N/A | Define a function to run after the user dismisses the modal. Passes dismiss `function(dismiss)` in as a param, value of **dismiss** can be `'cancel'`, `'overlay'`, `'close'`, `'timer'` |
|
162
|
+
| `title` | N/A | The title of the modal. It can either be added to the object under the key "title" or passed as the first parameter of the function. |
|
163
|
+
| `text` | N/A | A description for the modal. It can either be added to the object under the key "text" or passed as the second parameter of the function. |
|
164
|
+
| `html` | N/A | A HTML description for the modal. If `text` and `html` parameters are provided in the same time, "text" will be used. |
|
165
|
+
| `type ` | N/A | The type of the modal. SweetAlert2 comes with [5 built-in types](#modal-types) which will show a corresponding icon animation: `warning`, `error`, `success`, `info` and `question`. It can either be put in the array under the key `type` or passed as the third parameter of the function. |
|
166
|
+
| `custom_class` | N/A | A custom CSS class for the modal. |
|
167
|
+
| `animation` | `true` | If set to `false`, modal CSS animation will be disabled. |
|
168
|
+
| `allow_outside_click` | `true` | If set to `false`, the user can't dismiss the modal by clicking outside it. |
|
169
|
+
| `allow_escape_key` | `true` | If set to `false`, the user can't dismiss the modal by pressing the Escape key. |
|
170
|
+
| `show_confirm_button` | `true` | If set to `false`, a "Confirm"-button will not be shown. It can be useful when you're using `html` parameter for custom HTML description. |
|
171
|
+
| `show_cancel_button` | `false` | If set to `true`, a "Cancel"-button will be shown, which the user can click on to dismiss the modal. |
|
172
|
+
| `confirm_button_text` | `"OK"` | Use this to change the text on the "Confirm"-button. |
|
173
|
+
| `cancel_button_text` | `"Cancel"` | Use this to change the text on the "Cancel"-button. |
|
174
|
+
| `confirm_button_color` | `"#3085d6"` | Use this to change the background color of the "Confirm"-button (must be a HEX value). |
|
175
|
+
| `cancel_button_color` | `"#aaa"` | Use this to change the background color of the "Cancel"-button (must be a HEX value). |
|
176
|
+
| `confirm_button_class` | N/A | A custom CSS class for the "Confirm"-button. |
|
177
|
+
| `cancel_button_class` | N/A | A custom CSS class for the "Cancel"-button. |
|
178
|
+
| `buttons_styling` | `true` | Apply default swal2 styling to buttons. If you want to use your own classes (e.g. Bootstrap classes) set this parameter to `false`. |
|
179
|
+
| `reverse_buttons` | `false` | Set to `true` if you want to invert default buttons positions. |
|
180
|
+
| `show_close_button` | `false` | Set to `true` to show close button in top right corner of the modal. |
|
181
|
+
| `show_loader_on_confirm` | `false` | Set to `true` to disable buttons and show that something is loading. Useful for AJAX requests. |
|
182
|
+
| `pre_confirm` | N/A | Function to execute before confirm, should return Promise, see <a href="https://limonte.github.io/sweetalert2/#ajax-request">usage example</a>. |
|
183
|
+
| `image_url` | N/A | Add a customized icon for the modal. Should contain a string with the path or URL to the image. |
|
184
|
+
| `image_width` | N/A | If image_url is set, you can specify image_width to describes image width in px. |
|
185
|
+
| `image_height` | N/A | Custom image height in px. |
|
186
|
+
| `image_class` | N/A | A custom CSS class for the customized icon. |
|
187
|
+
| `timer` | N/A | Auto close timer of the modal. Set in ms (milliseconds). |
|
188
|
+
| `width` | `500` | Modal window width, including paddings (`box-sizing: border-box`). |
|
189
|
+
| `padding` | `20` | Modal window padding. |
|
190
|
+
| `background` | `"#fff"` | Modal window background (CSS `background` property). |
|
191
|
+
| `input` | N/A | Input field type, can be `"text"`, `"email"`, `"password"`, `"textarea"`, `"select"`, `"radio"`, `"checkbox"` and `"file"`. |
|
192
|
+
| `input_placeholder` | N/A | Input field placeholder. |
|
193
|
+
| `input_value` | N/A | Input field initial value. |
|
194
|
+
| `input_options` | N/A | If `input` parameter is set to `"select"` or `"radio"`, you can provide options. Object keys will represent options values, object values will represent options text values. |
|
195
|
+
| `input_auto_trim` | `true` | Automatically remove whitespaces from both ends of a result string. Set this parameter to `false` to disable auto-trimming. |
|
196
|
+
| `input_validator` | N/A | Validator for input field, should return Promise, see <a href="https://limonte.github.io/sweetalert2/#select-box">usage example</a>. |
|
197
|
+
| `input_class` | N/A | A custom CSS class for the input field. |
|
198
|
+
| `on_open` | N/A | Function to run when modal opens, provides modal DOM element as first param. |
|
199
|
+
| `on_close` | N/A | Function to run when modal closes, provides modal DOM element as first param. |
|
200
|
+
**N/A** means that the value isn't submitted unless defined
|
201
|
+
|
202
|
+
Please refer to the [SweetAlert2 Documentation](https://limonte.github.io/sweetalert2/) for the correct values
|
203
|
+
|
204
|
+
|
205
|
+
Modal Types
|
206
|
+
-----------
|
207
|
+
|
208
|
+
| `success` | `error` | `warning` | `info` | `question` |
|
209
|
+
| ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
|
210
|
+
| ![](https://raw.github.com/limonte/sweetalert2/master/images/swal2-success.png) | ![](https://raw.github.com/limonte/sweetalert2/master/images/swal2-error.png) | ![](https://raw.github.com/limonte/sweetalert2/master/images/swal2-warning.png) | ![](https://raw.github.com/limonte/sweetalert2/master/images/swal2-info.png) | ![](https://raw.github.com/limonte/sweetalert2/master/images/swal2-question.png) |
|
211
|
+
|
212
|
+
Browser compatibility
|
213
|
+
---------------------
|
214
|
+
|
215
|
+
SweetAlert2 works in most major browsers (yes, even IE). Some details:
|
216
|
+
|
217
|
+
- **IE: 10+**, Promise polyfill should be included (see [SweetAlert2 usage example](https://github.com/limonte/sweetalert2/blob/master/README.md#usage)).
|
218
|
+
- **Microsoft Edge: 12+**
|
219
|
+
- **Safari: 4+**
|
220
|
+
- **Firefox: 4+**
|
221
|
+
- **Chrome 14+**
|
222
|
+
- **Opera: 15+**
|
data/Rakefile
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
var sweetAlertConfirmDefaults = sweetAlertConfirmDefaults || {};
|
2
|
+
sweetAlertConfirmDefaults.sweetSelector = sweetAlertConfirmDefaults.sweetSelector || '[data-swal]';
|
3
|
+
|
4
|
+
var sweetAlertConfirm = function(event) {
|
5
|
+
var $linkToConfirm = $(this);
|
6
|
+
|
7
|
+
var swalOptions = {
|
8
|
+
animation: sweetAlertConfirmDefaults.animation || true,
|
9
|
+
allowOutsideClick: sweetAlertConfirmDefaults.allowOutsideClick || true,
|
10
|
+
allowEscapeKey: sweetAlertConfirmDefaults.allowEscapeKey || true,
|
11
|
+
showConfirmButton: sweetAlertConfirmDefaults.showConfirmButton || true,
|
12
|
+
showCancelButton: sweetAlertConfirmDefaults.showCancelButton || true,
|
13
|
+
confirmButtonText: sweetAlertConfirmDefaults.confirmButtonText || "OK",
|
14
|
+
cancelButtonText: sweetAlertConfirmDefaults.cancelButtonText || "Cancel",
|
15
|
+
confirmButtonColor: sweetAlertConfirmDefaults.confirmButtonColor || "#3085d6",
|
16
|
+
cancelButtonColor: sweetAlertConfirmDefaults.cancelButtonColor || "#aaa",
|
17
|
+
buttonsStyling: sweetAlertConfirmDefaults.buttonsStyling || true,
|
18
|
+
reverseButtons: sweetAlertConfirmDefaults.reverseButtons || false,
|
19
|
+
showCloseButton: sweetAlertConfirmDefaults.showCloseButton || false,
|
20
|
+
showLoaderOnConfirm: sweetAlertConfirmDefaults.showLoaderOnConfirm || false,
|
21
|
+
preConfirm: sweetAlertConfirmDefaults.preConfirm || false,
|
22
|
+
width: sweetAlertConfirmDefaults.width || 500,
|
23
|
+
padding: sweetAlertConfirmDefaults.padding || 20,
|
24
|
+
background: sweetAlertConfirmDefaults.background || '#fff',
|
25
|
+
inputAutoTrim: sweetAlertConfirmDefaults.inputAutoTrim || true,
|
26
|
+
};
|
27
|
+
|
28
|
+
var canBeNullOptions = [
|
29
|
+
'title',
|
30
|
+
'text',
|
31
|
+
'html',
|
32
|
+
'type',
|
33
|
+
'customClass',
|
34
|
+
'confirmButtonClass',
|
35
|
+
'cancelButtonClass',
|
36
|
+
'imageUrl',
|
37
|
+
'imageWidth',
|
38
|
+
'imageHeight',
|
39
|
+
'imageClass',
|
40
|
+
'timer',
|
41
|
+
'input',
|
42
|
+
'inputPlaceholder',
|
43
|
+
'inputValue',
|
44
|
+
'inputOptions',
|
45
|
+
'inputValidator',
|
46
|
+
'inputClass',
|
47
|
+
'onOpen',
|
48
|
+
'onClose'
|
49
|
+
]
|
50
|
+
|
51
|
+
$.each(canBeNullOptions, function(index, option) {
|
52
|
+
if(sweetAlertConfirmDefaults[option]) {
|
53
|
+
swalOptions[option] = sweetAlertConfirmDefaults[option]
|
54
|
+
};
|
55
|
+
});
|
56
|
+
|
57
|
+
var remoteSubmit =
|
58
|
+
sweetAlertConfirmDefaults.remote || $linkToConfirm.data('swal').remote || false
|
59
|
+
|
60
|
+
var swalOptionsMappings = {
|
61
|
+
"title":"title",
|
62
|
+
"text":"text",
|
63
|
+
"html":"html",
|
64
|
+
"type":"type",
|
65
|
+
"custom_class":"customClass",
|
66
|
+
"animation":"animation",
|
67
|
+
"allow_outside_click":"allowOutsideClick",
|
68
|
+
"allow_escape_key":"allowEscapeKey",
|
69
|
+
"show_confirm_button":"showConfirmButton",
|
70
|
+
"show_cancel_button":"showCancelButton",
|
71
|
+
"confirm_button_text":"confirmButtonText",
|
72
|
+
"cancel_button_text":"cancelButtonText",
|
73
|
+
"confirm_button_color":"confirmButtonColor",
|
74
|
+
"cancel_button_color":"cancelButtonColor",
|
75
|
+
"confirm_button_class":"confirmButtonClass",
|
76
|
+
"cancel_button_class":"cancelButtonClass",
|
77
|
+
"buttons_styling":"buttonsStyling",
|
78
|
+
"reverse_buttons":"reverseButtons",
|
79
|
+
"show_close_button":"showCloseButton",
|
80
|
+
"show_loader_on_confirm":"showLoaderOnConfirm",
|
81
|
+
"pre_confirm":"preConfirm",
|
82
|
+
"image_url":"imageUrl",
|
83
|
+
"image_width":"imageWidth",
|
84
|
+
"image_height":"imageHeight",
|
85
|
+
"image_class":"imageClass",
|
86
|
+
"timer":"timer",
|
87
|
+
"width":"width",
|
88
|
+
"padding":"padding",
|
89
|
+
"background":"background",
|
90
|
+
"input":"input",
|
91
|
+
"input_placeholder":"inputPlaceholder",
|
92
|
+
"input_value":"inputValue",
|
93
|
+
"input_options":"inputOptions",
|
94
|
+
"input_auto_trim":"inputAutoTrim",
|
95
|
+
"input_validator":"inputValidator",
|
96
|
+
"input_class":"inputClass",
|
97
|
+
"on_open":"onOpen",
|
98
|
+
"on_close":"onClose",
|
99
|
+
};
|
100
|
+
|
101
|
+
function afterConfirmCallback() {
|
102
|
+
if (afterConfirm) {
|
103
|
+
window[afterConfirm]();
|
104
|
+
return false
|
105
|
+
};
|
106
|
+
|
107
|
+
if (remoteSubmit === true) {
|
108
|
+
$.rails.handleRemote($linkToConfirm)
|
109
|
+
} else if(swalOptions['method'] !== undefined) {
|
110
|
+
$.rails.handleMethod($linkToConfirm);
|
111
|
+
} else {
|
112
|
+
if($linkToConfirm.attr('type') == 'submit'){
|
113
|
+
var name = $linkToConfirm.attr('name'),
|
114
|
+
data = name ? {name: name, value:$linkToConfirm.val()} : null;
|
115
|
+
$linkToConfirm.closest('form').data('ujs:submit-button', data);
|
116
|
+
$linkToConfirm.closest('form').submit();
|
117
|
+
} else {
|
118
|
+
window.location.href = $linkToConfirm.attr('href');
|
119
|
+
};
|
120
|
+
};
|
121
|
+
}
|
122
|
+
|
123
|
+
function afterDismissCallback(dismiss) {
|
124
|
+
if(afterDismiss) {
|
125
|
+
window[afterDismiss](dismiss)
|
126
|
+
return false
|
127
|
+
}
|
128
|
+
};
|
129
|
+
|
130
|
+
var skipConfirm = $linkToConfirm.data('swal').skip_confirm || null;
|
131
|
+
|
132
|
+
if(skipConfirm != null) {
|
133
|
+
if(skipConfirm === true || window[skipConfirm]($linkToConfirm) === true) {
|
134
|
+
return afterAlertCallback(true);
|
135
|
+
};
|
136
|
+
};
|
137
|
+
|
138
|
+
var optionKeys = [];
|
139
|
+
for(var option in swalOptionsMappings) { optionKeys.push(option) }
|
140
|
+
|
141
|
+
$.each($linkToConfirm.data('swal'), function(key, val){
|
142
|
+
if ($.inArray(key, optionKeys) >= 0) {
|
143
|
+
swalOptions[swalOptionsMappings[key]] = val
|
144
|
+
}
|
145
|
+
});
|
146
|
+
|
147
|
+
var afterConfirm = sweetAlertConfirmDefaults.afterConfirm || $linkToConfirm.data('swal').after_confirm || null
|
148
|
+
var afterDismiss = sweetAlertConfirmDefaults.afterDismiss || $linkToConfirm.data('swal').after_dismiss || null
|
149
|
+
|
150
|
+
swal(swalOptions).then(afterConfirmCallback, afterDismissCallback);
|
151
|
+
return false;
|
152
|
+
};
|
153
|
+
|
154
|
+
$(document).on('ready turbolinks:load page:update ajaxComplete', function() {
|
155
|
+
$(sweetAlertConfirmDefaults.sweetSelector).on('click', sweetAlertConfirm);
|
156
|
+
});
|
157
|
+
|
158
|
+
$(document).on('ready turbolinks:load page:load', function() {
|
159
|
+
//To avoid "Uncaught TypeError: Cannot read property 'querySelector' of null" on turbolinks
|
160
|
+
if (typeof window.sweetAlertInitialize === 'function') {
|
161
|
+
window.sweetAlertInitialize();
|
162
|
+
};
|
163
|
+
});
|