sweetalert-rails 0.1.0 → 0.1.1
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 +13 -5
- data/lib/sweetalert-rails/version.rb +1 -1
- data/vendor/assets/javascripts/sweet-alert.js +118 -63
- data/vendor/assets/stylesheets/sweet-alert.css +3 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjAyNTkyZDI4MDNiYmI5NzcyMDVhYjBhNzJjNzVkYmFkMWQxNzU5MA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YmUyZWQ5YmIyYjljOTk0OWMyMDAxZTEyOWZkNTU2ZDE0Mjk1M2JiMw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NDNiMTRjNGU2YTlmOTBmZTdiNjFlMzdhNWMzZmExNmUyNzgxZGZiOWY2MmI1
|
10
|
+
MDUwNjFkYWZkMTNhM2RiZmJiNjg0M2FlMWQ3MmQ1NTFkYWMxMTEwZmRiZTM0
|
11
|
+
ZmM5NjUwNzY1Zjk1YzdhYzYyM2I4MTRmYjlkZTQ1MmJhNWMxNjQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTc1ZTIxMDdjNjM5NDdiOGNmOWQwNmYxYmMxOWE0YzAzN2FkM2IxZmUxZTVj
|
14
|
+
YzM5MjY2MGE0NWRhMjBhYzRkZjI3NjUwN2E4YjI1YWY2NzE2NjU5ZTE1ZGFi
|
15
|
+
ZjUzZTZlZDZiMGNjYTliYTkxZTcyYzc0NTA3MjI0ZDgwOWI3NjA=
|
@@ -5,7 +5,22 @@
|
|
5
5
|
|
6
6
|
var modalClass = '.sweet-alert',
|
7
7
|
overlayClass = '.sweet-overlay',
|
8
|
-
alertTypes = ['error', 'warning', 'info', 'success']
|
8
|
+
alertTypes = ['error', 'warning', 'info', 'success'],
|
9
|
+
defaultParams = {
|
10
|
+
title: '',
|
11
|
+
text: '',
|
12
|
+
type: null,
|
13
|
+
allowOutsideClick: false,
|
14
|
+
showCancelButton: false,
|
15
|
+
closeOnConfirm: true,
|
16
|
+
closeOnCancel: true,
|
17
|
+
confirmButtonText: 'OK',
|
18
|
+
confirmButtonColor: '#AEDEF4',
|
19
|
+
cancelButtonText: 'Cancel',
|
20
|
+
imageUrl: null,
|
21
|
+
imageSize: null,
|
22
|
+
timer: null
|
23
|
+
};
|
9
24
|
|
10
25
|
|
11
26
|
/*
|
@@ -86,19 +101,21 @@
|
|
86
101
|
return ('-' + parseInt(height / 2 + padding) + 'px');
|
87
102
|
},
|
88
103
|
fadeIn = function(elem, interval) {
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
104
|
+
if(+elem.style.opacity < 1) {
|
105
|
+
interval = interval || 16;
|
106
|
+
elem.style.opacity = 0;
|
107
|
+
elem.style.display = 'block';
|
108
|
+
var last = +new Date();
|
109
|
+
var tick = function() {
|
110
|
+
elem.style.opacity = +elem.style.opacity + (new Date() - last) / 100;
|
111
|
+
last = +new Date();
|
112
|
+
|
113
|
+
if (+elem.style.opacity < 1) {
|
114
|
+
setTimeout(tick, interval);
|
115
|
+
}
|
116
|
+
};
|
117
|
+
tick();
|
118
|
+
}
|
102
119
|
},
|
103
120
|
fadeOut = function(elem, interval) {
|
104
121
|
interval = interval || 16;
|
@@ -131,11 +148,11 @@
|
|
131
148
|
// Fallback
|
132
149
|
var evt = document.createEvent('MouseEvents');
|
133
150
|
evt.initEvent('click', false, false);
|
134
|
-
node.dispatchEvent(evt);
|
151
|
+
node.dispatchEvent(evt);
|
135
152
|
} else if( document.createEventObject ) {
|
136
|
-
node.fireEvent('onclick') ;
|
153
|
+
node.fireEvent('onclick') ;
|
137
154
|
} else if (typeof node.onclick === 'function' ) {
|
138
|
-
node.onclick();
|
155
|
+
node.onclick();
|
139
156
|
}
|
140
157
|
},
|
141
158
|
stopEventPropagation = function(e) {
|
@@ -158,7 +175,7 @@
|
|
158
175
|
* Add modal + overlay to DOM
|
159
176
|
*/
|
160
177
|
|
161
|
-
function
|
178
|
+
window.sweetAlertInitialize = function() {
|
162
179
|
var sweetHTML = '<div class="sweet-overlay" tabIndex="-1"></div><div class="sweet-alert" tabIndex="-1"><div class="icon error"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div><div class="icon warning"> <span class="body"></span> <span class="dot"></span> </div> <div class="icon info"></div> <div class="icon success"> <span class="line tip"></span> <span class="line long"></span> <div class="placeholder"></div> <div class="fix"></div> </div> <div class="icon custom"></div> <h2>Title</h2><p>Text</p><button class="cancel" tabIndex="2">Cancel</button><button class="confirm" tabIndex="1">OK</button></div>',
|
163
180
|
sweetWrap = document.createElement('div');
|
164
181
|
|
@@ -169,41 +186,25 @@
|
|
169
186
|
|
170
187
|
// For development use only!
|
171
188
|
/*jQuery.ajax({
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
189
|
+
url: '../lib/sweet-alert.html', // Change path depending on file location
|
190
|
+
dataType: 'html'
|
191
|
+
})
|
192
|
+
.done(function(html) {
|
193
|
+
jQuery('body').append(html);
|
194
|
+
});*/
|
178
195
|
}
|
179
196
|
|
180
|
-
|
181
|
-
|
182
197
|
/*
|
183
198
|
* Global sweetAlert function
|
184
199
|
*/
|
185
200
|
|
186
201
|
window.sweetAlert = window.swal = function() {
|
187
|
-
|
188
|
-
// Default parameters
|
189
|
-
var params = {
|
190
|
-
title: '',
|
191
|
-
text: '',
|
192
|
-
type: null,
|
193
|
-
allowOutsideClick: false,
|
194
|
-
showCancelButton: false,
|
195
|
-
confirmButtonText: 'OK',
|
196
|
-
confirmButtonColor: '#AEDEF4',
|
197
|
-
cancelButtonText: 'Cancel',
|
198
|
-
imageUrl: null,
|
199
|
-
imageSize: null
|
200
|
-
};
|
201
|
-
|
202
202
|
if (arguments[0] === undefined) {
|
203
203
|
window.console.error('sweetAlert expects at least 1 attribute!');
|
204
204
|
return false;
|
205
205
|
}
|
206
206
|
|
207
|
+
var params = extend({}, defaultParams);
|
207
208
|
|
208
209
|
switch (typeof arguments[0]) {
|
209
210
|
|
@@ -221,19 +222,21 @@
|
|
221
222
|
}
|
222
223
|
|
223
224
|
params.title = arguments[0].title;
|
224
|
-
params.text = arguments[0].text ||
|
225
|
-
params.type = arguments[0].type ||
|
226
|
-
params.allowOutsideClick = arguments[0].allowOutsideClick ||
|
227
|
-
params.showCancelButton = arguments[0].showCancelButton
|
225
|
+
params.text = arguments[0].text || defaultParams.text;
|
226
|
+
params.type = arguments[0].type || defaultParams.type;
|
227
|
+
params.allowOutsideClick = arguments[0].allowOutsideClick || defaultParams.allowOutsideClick;
|
228
|
+
params.showCancelButton = arguments[0].showCancelButton !== undefined ? arguments[0].showCancelButton : defaultParams.showCancelButton;
|
229
|
+
params.closeOnConfirm = arguments[0].closeOnConfirm !== undefined ? arguments[0].closeOnConfirm : defaultParams.closeOnConfirm;
|
230
|
+
params.closeOnCancel = arguments[0].closeOnCancel !== undefined ? arguments[0].closeOnCancel : defaultParams.closeOnCancel;
|
231
|
+
params.timer = arguments[0].timer || defaultParams.timer;
|
228
232
|
|
229
233
|
// Show "Confirm" instead of "OK" if cancel button is visible
|
230
|
-
params.confirmButtonText = (
|
231
|
-
|
232
|
-
params.
|
233
|
-
params.
|
234
|
-
params.
|
235
|
-
params.
|
236
|
-
params.imageSize = arguments[0].imageSize || params.imageSize;
|
234
|
+
params.confirmButtonText = (defaultParams.showCancelButton) ? 'Confirm' : defaultParams.confirmButtonText;
|
235
|
+
params.confirmButtonText = arguments[0].confirmButtonText || defaultParams.confirmButtonText;
|
236
|
+
params.confirmButtonColor = arguments[0].confirmButtonColor || defaultParams.confirmButtonColor;
|
237
|
+
params.cancelButtonText = arguments[0].cancelButtonText || defaultParams.cancelButtonText;
|
238
|
+
params.imageUrl = arguments[0].imageUrl || defaultParams.imageUrl;
|
239
|
+
params.imageSize = arguments[0].imageSize || defaultParams.imageSize;
|
237
240
|
params.doneFunction = arguments[1] || null;
|
238
241
|
|
239
242
|
break;
|
@@ -244,8 +247,6 @@
|
|
244
247
|
|
245
248
|
}
|
246
249
|
|
247
|
-
//console.log(params.confirmButtonColor);
|
248
|
-
|
249
250
|
setParameters(params);
|
250
251
|
fixVerticalPosition();
|
251
252
|
openModal();
|
@@ -294,10 +295,30 @@
|
|
294
295
|
}
|
295
296
|
break;
|
296
297
|
case ("click"):
|
297
|
-
if (targetedConfirm && doneFunctionExists && modalIsVisible) {
|
298
|
-
|
298
|
+
if (targetedConfirm && doneFunctionExists && modalIsVisible) { // Clicked "confirm"
|
299
|
+
|
300
|
+
params.doneFunction(true);
|
301
|
+
|
302
|
+
if (params.closeOnConfirm) {
|
303
|
+
closeModal();
|
304
|
+
}
|
305
|
+
} else if (doneFunctionExists && modalIsVisible) { // Clicked "cancel"
|
306
|
+
|
307
|
+
// Check if callback function expects a parameter (to track cancel actions)
|
308
|
+
var functionAsStr = String(params.doneFunction).replace(/\s/g, '');
|
309
|
+
var functionHandlesCancel = functionAsStr.substring(0, 9) === "function(" && functionAsStr.substring(9, 10) !== ")";
|
310
|
+
|
311
|
+
if (functionHandlesCancel) {
|
312
|
+
params.doneFunction(false);
|
313
|
+
}
|
314
|
+
|
315
|
+
if (params.closeOnCancel) {
|
316
|
+
closeModal();
|
317
|
+
}
|
318
|
+
} else {
|
319
|
+
closeModal();
|
299
320
|
}
|
300
|
-
|
321
|
+
|
301
322
|
break;
|
302
323
|
}
|
303
324
|
};
|
@@ -435,11 +456,25 @@
|
|
435
456
|
if (lastFocusedButton !== undefined) {
|
436
457
|
lastFocusedButton.focus();
|
437
458
|
lastFocusedButton = undefined;
|
438
|
-
}
|
459
|
+
}
|
439
460
|
}, 0);
|
440
461
|
};
|
441
462
|
};
|
442
463
|
|
464
|
+
/**
|
465
|
+
* Set default params for each popup
|
466
|
+
* @param {Object} userParams
|
467
|
+
*/
|
468
|
+
window.swal.setDefaults = function(userParams) {
|
469
|
+
if (!userParams) {
|
470
|
+
throw new Error('userParams is required');
|
471
|
+
}
|
472
|
+
if (typeof userParams !== 'object') {
|
473
|
+
throw new Error('userParams has to be a object');
|
474
|
+
}
|
475
|
+
|
476
|
+
extend(defaultParams, userParams);
|
477
|
+
};
|
443
478
|
|
444
479
|
/*
|
445
480
|
* Set type, text and actions on modal
|
@@ -556,13 +591,16 @@
|
|
556
591
|
// Done-function
|
557
592
|
var hasDoneFunction = (params.doneFunction) ? true : false;
|
558
593
|
modal.setAttribute('data-has-done-function', hasDoneFunction);
|
594
|
+
|
595
|
+
// Close timer
|
596
|
+
modal.setAttribute('data-timer', params.timer);
|
559
597
|
}
|
560
598
|
|
561
599
|
|
562
600
|
/*
|
563
601
|
* Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color)
|
564
602
|
*/
|
565
|
-
|
603
|
+
|
566
604
|
function colorLuminance(hex, lum) {
|
567
605
|
// Validate hex string
|
568
606
|
hex = String(hex).replace(/[^0-9a-f]/gi, '');
|
@@ -582,6 +620,16 @@
|
|
582
620
|
return rgb;
|
583
621
|
}
|
584
622
|
|
623
|
+
function extend(a, b){
|
624
|
+
for (var key in b) {
|
625
|
+
if (b.hasOwnProperty(key)) {
|
626
|
+
a[key] = b[key];
|
627
|
+
}
|
628
|
+
}
|
629
|
+
|
630
|
+
return a;
|
631
|
+
}
|
632
|
+
|
585
633
|
function hexToRgb(hex) {
|
586
634
|
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
587
635
|
return result ? parseInt(result[1], 16) + ', ' + parseInt(result[2], 16) + ', ' + parseInt(result[3], 16) : null;
|
@@ -613,6 +661,13 @@
|
|
613
661
|
setTimeout(function() {
|
614
662
|
addClass(modal, 'visible');
|
615
663
|
}, 500);
|
664
|
+
|
665
|
+
var timer = modal.getAttribute('data-timer');
|
666
|
+
if (timer !== "null") {
|
667
|
+
setTimeout(function() {
|
668
|
+
closeModal();
|
669
|
+
}, timer);
|
670
|
+
}
|
616
671
|
}
|
617
672
|
|
618
673
|
function closeModal() {
|
@@ -668,19 +723,19 @@
|
|
668
723
|
*/
|
669
724
|
|
670
725
|
(function () {
|
671
|
-
if (document.readyState === "complete" || document.readyState === "interactive") {
|
672
|
-
|
726
|
+
if (document.readyState === "complete" || document.readyState === "interactive" && document.body) {
|
727
|
+
sweetAlertInitialize();
|
673
728
|
} else {
|
674
729
|
if (document.addEventListener) {
|
675
730
|
document.addEventListener('DOMContentLoaded', function factorial() {
|
676
731
|
document.removeEventListener('DOMContentLoaded', arguments.callee, false);
|
677
|
-
|
732
|
+
sweetAlertInitialize();
|
678
733
|
}, false);
|
679
734
|
} else if (document.attachEvent) {
|
680
735
|
document.attachEvent('onreadystatechange', function() {
|
681
736
|
if (document.readyState === 'complete') {
|
682
737
|
document.detachEvent('onreadystatechange', arguments.callee);
|
683
|
-
|
738
|
+
sweetAlertInitialize();
|
684
739
|
}
|
685
740
|
});
|
686
741
|
}
|
@@ -72,6 +72,8 @@
|
|
72
72
|
background-color: #b6b6b6; }
|
73
73
|
.sweet-alert button.cancel:focus {
|
74
74
|
box-shadow: rgba(197, 205, 211, 0.8) 0px 0px 2px, rgba(0, 0, 0, 0.0470588) 0px 0px 0px 1px inset !important; }
|
75
|
+
.sweet-alert button::-moz-focus-inner {
|
76
|
+
border: 0; }
|
75
77
|
.sweet-alert[data-has-cancel-button=false] button {
|
76
78
|
box-shadow: none !important; }
|
77
79
|
.sweet-alert .icon {
|
@@ -153,6 +155,7 @@
|
|
153
155
|
width: 60px;
|
154
156
|
height: 120px;
|
155
157
|
background: white;
|
158
|
+
-webkit-transform: rotate(45deg);
|
156
159
|
transform: rotate(45deg); }
|
157
160
|
.sweet-alert .icon.success::before {
|
158
161
|
border-radius: 120px 0 0 120px;
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sweetalert-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Sharshenov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.1.0
|
27
27
|
description: This gem provides SweerAlert for your Rails application.
|
@@ -31,7 +31,7 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
-
|
34
|
+
- .gitignore
|
35
35
|
- Gemfile
|
36
36
|
- LICENSE.txt
|
37
37
|
- README.md
|
@@ -52,12 +52,12 @@ require_paths:
|
|
52
52
|
- lib
|
53
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - ! '>='
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ! '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|