abstracted 0.0.6 → 0.0.14
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/Gemfile +1 -1
- data/Gemfile.lock +11 -8
- data/app/assets/javascripts/abstract_resources.js +29 -25
- data/app/assets/javascripts/crud.js.coffee +174 -29
- data/app/assets/javascripts/initializers.js.coffee +403 -58
- data/app/assets/javascripts/pagescrolling.js.coffee +92 -0
- data/app/assets/stylesheets/abstract_resources.css +5 -0
- data/app/assets/stylesheets/scaffold.css +4 -2
- data/app/assets/stylesheets/selectize.css.scss +0 -0
- data/app/controllers/abstract_resources_controller.rb +473 -134
- data/app/controllers/application_controller.rb +22 -7
- data/app/helpers/abstract_resources_helper.rb +515 -9
- data/app/helpers/fab_button_helper.rb +82 -0
- data/app/models/abstract_resource.rb +141 -89
- data/app/models/ancestry_abstract_resource.rb +27 -0
- data/app/models/concerns/roleable.rb +1 -1
- data/app/policies/abstract_resource_policy.rb +25 -0
- data/app/views/abstract_resources/_title.html.haml +2 -0
- data/app/views/abstract_resources/activate.html.haml +5 -0
- data/app/views/abstract_resources/attach.html.haml +6 -0
- data/app/views/abstract_resources/deactivate.html.haml +5 -0
- data/app/views/abstract_resources/defer.html.haml +5 -0
- data/app/views/abstract_resources/destroy.js.haml +2 -1
- data/app/views/abstract_resources/detach.html.haml +5 -0
- data/app/views/abstract_resources/edit.html.haml +4 -9
- data/app/views/abstract_resources/error.html.haml +2 -0
- data/app/views/abstract_resources/error.js.haml +2 -0
- data/app/views/abstract_resources/index.html.haml +27 -0
- data/app/views/abstract_resources/index.js.haml +2 -0
- data/app/views/abstract_resources/new.html.haml +4 -10
- data/app/views/abstract_resources/prefer.html.haml +5 -0
- data/app/views/abstract_resources/print.html.haml +2 -0
- data/app/views/abstract_resources/print.js.haml +2 -0
- data/app/views/abstract_resources/show.html.haml +5 -11
- data/app/views/layouts/_messages.html.haml +1 -0
- data/app/views/layouts/_navigation.html.haml +13 -0
- data/bower.json +34 -0
- data/config/initializers/exception.rb +19 -0
- data/config/initializers/pundit.rb +22 -0
- data/config/routes.rb +24 -0
- data/lib/abstracted.rb +3 -0
- data/lib/abstracted/version.rb +1 -1
- data/lib/abstracted_responder.rb +1 -0
- data/lib/exceptions.rb +61 -0
- data/vendor/assets/components/jquery/.bower.json +38 -0
- data/vendor/assets/components/jquery/MIT-LICENSE.txt +21 -0
- data/vendor/assets/components/jquery/bower.json +28 -0
- data/vendor/assets/components/jquery/dist/jquery.js +9210 -0
- data/vendor/assets/components/jquery/dist/jquery.min.js +5 -0
- data/vendor/assets/components/jquery/dist/jquery.min.map +1 -0
- data/vendor/assets/components/jquery/src/ajax.js +786 -0
- data/vendor/assets/components/jquery/src/ajax/jsonp.js +89 -0
- data/vendor/assets/components/jquery/src/ajax/load.js +75 -0
- data/vendor/assets/components/jquery/src/ajax/parseJSON.js +13 -0
- data/vendor/assets/components/jquery/src/ajax/parseXML.js +28 -0
- data/vendor/assets/components/jquery/src/ajax/script.js +64 -0
- data/vendor/assets/components/jquery/src/ajax/var/nonce.js +5 -0
- data/vendor/assets/components/jquery/src/ajax/var/rquery.js +3 -0
- data/vendor/assets/components/jquery/src/ajax/xhr.js +136 -0
- data/vendor/assets/components/jquery/src/attributes.js +11 -0
- data/vendor/assets/components/jquery/src/attributes/attr.js +141 -0
- data/vendor/assets/components/jquery/src/attributes/classes.js +158 -0
- data/vendor/assets/components/jquery/src/attributes/prop.js +94 -0
- data/vendor/assets/components/jquery/src/attributes/support.js +35 -0
- data/vendor/assets/components/jquery/src/attributes/val.js +161 -0
- data/vendor/assets/components/jquery/src/callbacks.js +205 -0
- data/vendor/assets/components/jquery/src/core.js +502 -0
- data/vendor/assets/components/jquery/src/core/access.js +60 -0
- data/vendor/assets/components/jquery/src/core/init.js +123 -0
- data/vendor/assets/components/jquery/src/core/parseHTML.js +39 -0
- data/vendor/assets/components/jquery/src/core/ready.js +97 -0
- data/vendor/assets/components/jquery/src/core/var/rsingleTag.js +4 -0
- data/vendor/assets/components/jquery/src/css.js +450 -0
- data/vendor/assets/components/jquery/src/css/addGetHookIf.js +22 -0
- data/vendor/assets/components/jquery/src/css/curCSS.js +57 -0
- data/vendor/assets/components/jquery/src/css/defaultDisplay.js +70 -0
- data/vendor/assets/components/jquery/src/css/hiddenVisibleSelectors.js +15 -0
- data/vendor/assets/components/jquery/src/css/support.js +96 -0
- data/vendor/assets/components/jquery/src/css/swap.js +28 -0
- data/vendor/assets/components/jquery/src/css/var/cssExpand.js +3 -0
- data/vendor/assets/components/jquery/src/css/var/getStyles.js +12 -0
- data/vendor/assets/components/jquery/src/css/var/isHidden.js +13 -0
- data/vendor/assets/components/jquery/src/css/var/rmargin.js +3 -0
- data/vendor/assets/components/jquery/src/css/var/rnumnonpx.js +5 -0
- data/vendor/assets/components/jquery/src/data.js +178 -0
- data/vendor/assets/components/jquery/src/data/Data.js +181 -0
- data/vendor/assets/components/jquery/src/data/accepts.js +20 -0
- data/vendor/assets/components/jquery/src/data/var/data_priv.js +5 -0
- data/vendor/assets/components/jquery/src/data/var/data_user.js +5 -0
- data/vendor/assets/components/jquery/src/deferred.js +149 -0
- data/vendor/assets/components/jquery/src/deprecated.js +13 -0
- data/vendor/assets/components/jquery/src/dimensions.js +50 -0
- data/vendor/assets/components/jquery/src/effects.js +648 -0
- data/vendor/assets/components/jquery/src/effects/Tween.js +114 -0
- data/vendor/assets/components/jquery/src/effects/animatedSelector.js +13 -0
- data/vendor/assets/components/jquery/src/event.js +868 -0
- data/vendor/assets/components/jquery/src/event/ajax.js +13 -0
- data/vendor/assets/components/jquery/src/event/alias.js +39 -0
- data/vendor/assets/components/jquery/src/event/support.js +9 -0
- data/vendor/assets/components/jquery/src/exports/amd.js +24 -0
- data/vendor/assets/components/jquery/src/exports/global.js +32 -0
- data/vendor/assets/components/jquery/src/intro.js +44 -0
- data/vendor/assets/components/jquery/src/jquery.js +37 -0
- data/vendor/assets/components/jquery/src/manipulation.js +580 -0
- data/vendor/assets/components/jquery/src/manipulation/_evalUrl.js +18 -0
- data/vendor/assets/components/jquery/src/manipulation/support.js +32 -0
- data/vendor/assets/components/jquery/src/manipulation/var/rcheckableType.js +3 -0
- data/vendor/assets/components/jquery/src/offset.js +207 -0
- data/vendor/assets/components/jquery/src/outro.js +1 -0
- data/vendor/assets/components/jquery/src/queue.js +142 -0
- data/vendor/assets/components/jquery/src/queue/delay.js +22 -0
- data/vendor/assets/components/jquery/src/selector-native.js +172 -0
- data/vendor/assets/components/jquery/src/selector-sizzle.js +14 -0
- data/vendor/assets/components/jquery/src/selector.js +1 -0
- data/vendor/assets/components/jquery/src/serialize.js +111 -0
- data/vendor/assets/components/jquery/src/sizzle/dist/sizzle.js +2067 -0
- data/vendor/assets/components/jquery/src/sizzle/dist/sizzle.min.js +3 -0
- data/vendor/assets/components/jquery/src/sizzle/dist/sizzle.min.map +1 -0
- data/vendor/assets/components/jquery/src/traversing.js +199 -0
- data/vendor/assets/components/jquery/src/traversing/findFilter.js +100 -0
- data/vendor/assets/components/jquery/src/traversing/var/rneedsContext.js +6 -0
- data/vendor/assets/components/jquery/src/var/arr.js +3 -0
- data/vendor/assets/components/jquery/src/var/class2type.js +4 -0
- data/vendor/assets/components/jquery/src/var/concat.js +5 -0
- data/vendor/assets/components/jquery/src/var/hasOwn.js +5 -0
- data/vendor/assets/components/jquery/src/var/indexOf.js +5 -0
- data/vendor/assets/components/jquery/src/var/pnum.js +3 -0
- data/vendor/assets/components/jquery/src/var/push.js +5 -0
- data/vendor/assets/components/jquery/src/var/rnotwhite.js +3 -0
- data/vendor/assets/components/jquery/src/var/slice.js +5 -0
- data/vendor/assets/components/jquery/src/var/strundefined.js +3 -0
- data/vendor/assets/components/jquery/src/var/support.js +4 -0
- data/vendor/assets/components/jquery/src/var/toString.js +5 -0
- data/vendor/assets/components/jquery/src/wrap.js +79 -0
- data/vendor/assets/components/microplugin/.bower.json +38 -0
- data/vendor/assets/components/microplugin/.gitignore +2 -0
- data/vendor/assets/components/microplugin/.npmignore +3 -0
- data/vendor/assets/components/microplugin/README.md +115 -0
- data/vendor/assets/components/microplugin/bower.json +22 -0
- data/vendor/assets/components/microplugin/package.json +15 -0
- data/vendor/assets/components/microplugin/src/microplugin.js +135 -0
- data/vendor/assets/components/selectize/.bower.json +60 -0
- data/vendor/assets/components/selectize/.gitignore +5 -0
- data/vendor/assets/components/selectize/LICENSE +202 -0
- data/vendor/assets/components/selectize/README.md +105 -0
- data/vendor/assets/components/selectize/bower.json +40 -0
- data/vendor/assets/components/selectize/dist/css/selectize.bootstrap2.css +487 -0
- data/vendor/assets/components/selectize/dist/css/selectize.bootstrap3.css +401 -0
- data/vendor/assets/components/selectize/dist/css/selectize.css +317 -0
- data/vendor/assets/components/selectize/dist/css/selectize.default.css +387 -0
- data/vendor/assets/components/selectize/dist/css/selectize.legacy.css +364 -0
- data/vendor/assets/components/selectize/dist/js/selectize.js +3058 -0
- data/vendor/assets/components/selectize/dist/js/selectize.min.js +3 -0
- data/vendor/assets/components/selectize/dist/js/standalone/selectize.js +3667 -0
- data/vendor/assets/components/selectize/dist/js/standalone/selectize.min.js +3 -0
- data/vendor/assets/components/selectize/dist/less/plugins/drag_drop.less +16 -0
- data/vendor/assets/components/selectize/dist/less/plugins/dropdown_header.less +20 -0
- data/vendor/assets/components/selectize/dist/less/plugins/optgroup_columns.less +17 -0
- data/vendor/assets/components/selectize/dist/less/plugins/remove_button.less +37 -0
- data/vendor/assets/components/selectize/dist/less/selectize.bootstrap2.less +161 -0
- data/vendor/assets/components/selectize/dist/less/selectize.bootstrap3.less +150 -0
- data/vendor/assets/components/selectize/dist/less/selectize.default.less +84 -0
- data/vendor/assets/components/selectize/dist/less/selectize.legacy.less +75 -0
- data/vendor/assets/components/selectize/dist/less/selectize.less +295 -0
- data/vendor/assets/components/selectize/karma.conf.js +107 -0
- data/vendor/assets/components/sifter/.bower.json +44 -0
- data/vendor/assets/components/sifter/.gitignore +3 -0
- data/vendor/assets/components/sifter/.npmignore +4 -0
- data/vendor/assets/components/sifter/README.md +149 -0
- data/vendor/assets/components/sifter/bower.json +23 -0
- data/vendor/assets/components/sifter/package.json +48 -0
- data/vendor/assets/components/sifter/sifter.js +471 -0
- data/vendor/assets/components/sifter/sifter.min.js +2 -0
- data/vendor/assets/components/sweetalert/.bower.json +36 -0
- data/vendor/assets/components/sweetalert/.editorconfig +11 -0
- data/vendor/assets/components/sweetalert/.gitignore +5 -0
- data/vendor/assets/components/sweetalert/.jshintrc +11 -0
- data/vendor/assets/components/sweetalert/.travis.yml +6 -0
- data/vendor/assets/components/sweetalert/LICENSE +22 -0
- data/vendor/assets/components/sweetalert/README.md +157 -0
- data/vendor/assets/components/sweetalert/bower.json +25 -0
- data/vendor/assets/components/sweetalert/dev/gulpfile-wrap-template.js +18 -0
- data/vendor/assets/components/sweetalert/dev/ie9.css +23 -0
- data/vendor/assets/components/sweetalert/dev/loader-animation.css +209 -0
- data/vendor/assets/components/sweetalert/dev/modules/default-params.js +26 -0
- data/vendor/assets/components/sweetalert/dev/modules/handle-click.js +128 -0
- data/vendor/assets/components/sweetalert/dev/modules/handle-dom.js +161 -0
- data/vendor/assets/components/sweetalert/dev/modules/handle-key.js +73 -0
- data/vendor/assets/components/sweetalert/dev/modules/handle-swal-dom.js +148 -0
- data/vendor/assets/components/sweetalert/dev/modules/injected-html.js +69 -0
- data/vendor/assets/components/sweetalert/dev/modules/set-params.js +221 -0
- data/vendor/assets/components/sweetalert/dev/modules/utils.js +71 -0
- data/vendor/assets/components/sweetalert/dev/sweetalert.es6.js +311 -0
- data/vendor/assets/components/sweetalert/dev/sweetalert.scss +648 -0
- data/vendor/assets/components/sweetalert/dist/sweetalert-dev.js +1281 -0
- data/vendor/assets/components/sweetalert/dist/sweetalert.css +932 -0
- data/vendor/assets/components/sweetalert/dist/sweetalert.min.js +1 -0
- data/vendor/assets/components/sweetalert/example/example.css +442 -0
- data/vendor/assets/components/sweetalert/example/example.scss +580 -0
- data/vendor/assets/components/sweetalert/example/images/logo_big.png +0 -0
- data/vendor/assets/components/sweetalert/example/images/logo_big@2x.png +0 -0
- data/vendor/assets/components/sweetalert/example/images/logo_small.png +0 -0
- data/vendor/assets/components/sweetalert/example/images/logo_small@2x.png +0 -0
- data/vendor/assets/components/sweetalert/example/images/te-logo-small.svg +12 -0
- data/vendor/assets/components/sweetalert/example/images/thumbs-up.jpg +0 -0
- data/vendor/assets/components/sweetalert/example/images/vs_icon.png +0 -0
- data/vendor/assets/components/sweetalert/example/images/vs_icon@2x.png +0 -0
- data/vendor/assets/components/sweetalert/gulpfile.js +97 -0
- data/vendor/assets/components/sweetalert/index.html +584 -0
- data/vendor/assets/components/sweetalert/package.json +45 -0
- data/vendor/assets/components/sweetalert/sweetalert.gif +0 -0
- data/vendor/assets/components/sweetalert/test/index.html +20 -0
- data/vendor/assets/components/sweetalert/test/tests.js +143 -0
- data/vendor/assets/components/sweetalert/themes/facebook/facebook.css +111 -0
- data/vendor/assets/components/sweetalert/themes/facebook/facebook.scss +146 -0
- data/vendor/assets/components/sweetalert/themes/google/google.css +115 -0
- data/vendor/assets/components/sweetalert/themes/google/google.scss +148 -0
- data/vendor/assets/components/sweetalert/themes/twitter/twitter.css +140 -0
- data/vendor/assets/components/sweetalert/themes/twitter/twitter.scss +177 -0
- metadata +214 -5
- data/abstracted-0.0.4.gem +0 -0
- data/abstracted.gemspec +0 -51
- data/app/views/abstract_resources/index.html.erb +0 -1
@@ -0,0 +1,69 @@
|
|
1
|
+
var injectedHTML =
|
2
|
+
|
3
|
+
// Dark overlay
|
4
|
+
`<div class="sweet-overlay" tabIndex="-1"></div>` +
|
5
|
+
|
6
|
+
// Modal
|
7
|
+
`<div class="sweet-alert">` +
|
8
|
+
|
9
|
+
// Error icon
|
10
|
+
`<div class="sa-icon sa-error">
|
11
|
+
<span class="sa-x-mark">
|
12
|
+
<span class="sa-line sa-left"></span>
|
13
|
+
<span class="sa-line sa-right"></span>
|
14
|
+
</span>
|
15
|
+
</div>` +
|
16
|
+
|
17
|
+
// Warning icon
|
18
|
+
`<div class="sa-icon sa-warning">
|
19
|
+
<span class="sa-body"></span>
|
20
|
+
<span class="sa-dot"></span>
|
21
|
+
</div>` +
|
22
|
+
|
23
|
+
// Info icon
|
24
|
+
`<div class="sa-icon sa-info"></div>` +
|
25
|
+
|
26
|
+
// Success icon
|
27
|
+
`<div class="sa-icon sa-success">
|
28
|
+
<span class="sa-line sa-tip"></span>
|
29
|
+
<span class="sa-line sa-long"></span>
|
30
|
+
|
31
|
+
<div class="sa-placeholder"></div>
|
32
|
+
<div class="sa-fix"></div>
|
33
|
+
</div>` +
|
34
|
+
|
35
|
+
`<div class="sa-icon sa-custom"></div>` +
|
36
|
+
|
37
|
+
// Title, text and input
|
38
|
+
`<h2>Title</h2>
|
39
|
+
<p>Text</p>
|
40
|
+
<fieldset>
|
41
|
+
<input type="text" tabIndex="3" />
|
42
|
+
<div class="sa-input-error"></div>
|
43
|
+
</fieldset>` +
|
44
|
+
|
45
|
+
// Input errors
|
46
|
+
`<div class="sa-error-container">
|
47
|
+
<div class="icon">!</div>
|
48
|
+
<p>Not valid!</p>
|
49
|
+
</div>` +
|
50
|
+
|
51
|
+
// Cancel and confirm buttons
|
52
|
+
`<div class="sa-button-container">
|
53
|
+
<button class="cancel" tabIndex="2">Cancel</button>
|
54
|
+
<div class="sa-confirm-button-container">
|
55
|
+
<button class="confirm" tabIndex="1">OK</button>` +
|
56
|
+
|
57
|
+
// Loading animation
|
58
|
+
`<div class="la-ball-fall">
|
59
|
+
<div></div>
|
60
|
+
<div></div>
|
61
|
+
<div></div>
|
62
|
+
</div>
|
63
|
+
</div>
|
64
|
+
</div>` +
|
65
|
+
|
66
|
+
// End of modal
|
67
|
+
`</div>`;
|
68
|
+
|
69
|
+
export default injectedHTML;
|
@@ -0,0 +1,221 @@
|
|
1
|
+
var alertTypes = ['error', 'warning', 'info', 'success', 'input', 'prompt'];
|
2
|
+
|
3
|
+
import {
|
4
|
+
isIE8
|
5
|
+
} from './utils';
|
6
|
+
|
7
|
+
import {
|
8
|
+
getModal,
|
9
|
+
getInput,
|
10
|
+
setFocusStyle
|
11
|
+
} from './handle-swal-dom';
|
12
|
+
|
13
|
+
import {
|
14
|
+
hasClass, addClass, removeClass,
|
15
|
+
escapeHtml,
|
16
|
+
_show, show, _hide, hide
|
17
|
+
} from './handle-dom';
|
18
|
+
|
19
|
+
|
20
|
+
/*
|
21
|
+
* Set type, text and actions on modal
|
22
|
+
*/
|
23
|
+
var setParameters = function(params) {
|
24
|
+
var modal = getModal();
|
25
|
+
|
26
|
+
var $title = modal.querySelector('h2');
|
27
|
+
var $text = modal.querySelector('p');
|
28
|
+
var $cancelBtn = modal.querySelector('button.cancel');
|
29
|
+
var $confirmBtn = modal.querySelector('button.confirm');
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Title
|
33
|
+
*/
|
34
|
+
$title.innerHTML = params.html ? params.title : escapeHtml(params.title).split('\n').join('<br>');
|
35
|
+
|
36
|
+
/*
|
37
|
+
* Text
|
38
|
+
*/
|
39
|
+
$text.innerHTML = params.html ? params.text : escapeHtml(params.text || '').split('\n').join('<br>');
|
40
|
+
if (params.text) show($text);
|
41
|
+
|
42
|
+
/*
|
43
|
+
* Custom class
|
44
|
+
*/
|
45
|
+
if (params.customClass) {
|
46
|
+
addClass(modal, params.customClass);
|
47
|
+
modal.setAttribute('data-custom-class', params.customClass);
|
48
|
+
} else {
|
49
|
+
// Find previously set classes and remove them
|
50
|
+
let customClass = modal.getAttribute('data-custom-class');
|
51
|
+
removeClass(modal, customClass);
|
52
|
+
modal.setAttribute('data-custom-class', '');
|
53
|
+
}
|
54
|
+
|
55
|
+
/*
|
56
|
+
* Icon
|
57
|
+
*/
|
58
|
+
hide(modal.querySelectorAll('.sa-icon'));
|
59
|
+
|
60
|
+
if (params.type && !isIE8()) {
|
61
|
+
|
62
|
+
let validType = false;
|
63
|
+
|
64
|
+
for (let i = 0; i < alertTypes.length; i++) {
|
65
|
+
if (params.type === alertTypes[i]) {
|
66
|
+
validType = true;
|
67
|
+
break;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
if (!validType) {
|
72
|
+
logStr('Unknown alert type: ' + params.type);
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
|
76
|
+
let typesWithIcons = ['success', 'error', 'warning', 'info'];
|
77
|
+
let $icon;
|
78
|
+
|
79
|
+
if (typesWithIcons.indexOf(params.type) !== -1) {
|
80
|
+
$icon = modal.querySelector('.sa-icon.' + 'sa-' + params.type);
|
81
|
+
show($icon);
|
82
|
+
}
|
83
|
+
|
84
|
+
let $input = getInput();
|
85
|
+
|
86
|
+
// Animate icon
|
87
|
+
switch (params.type) {
|
88
|
+
|
89
|
+
case 'success':
|
90
|
+
addClass($icon, 'animate');
|
91
|
+
addClass($icon.querySelector('.sa-tip'), 'animateSuccessTip');
|
92
|
+
addClass($icon.querySelector('.sa-long'), 'animateSuccessLong');
|
93
|
+
break;
|
94
|
+
|
95
|
+
case 'error':
|
96
|
+
addClass($icon, 'animateErrorIcon');
|
97
|
+
addClass($icon.querySelector('.sa-x-mark'), 'animateXMark');
|
98
|
+
break;
|
99
|
+
|
100
|
+
case 'warning':
|
101
|
+
addClass($icon, 'pulseWarning');
|
102
|
+
addClass($icon.querySelector('.sa-body'), 'pulseWarningIns');
|
103
|
+
addClass($icon.querySelector('.sa-dot'), 'pulseWarningIns');
|
104
|
+
break;
|
105
|
+
|
106
|
+
case 'input':
|
107
|
+
case 'prompt':
|
108
|
+
$input.setAttribute('type', params.inputType);
|
109
|
+
$input.value = params.inputValue;
|
110
|
+
$input.setAttribute('placeholder', params.inputPlaceholder);
|
111
|
+
addClass(modal, 'show-input');
|
112
|
+
setTimeout(function () {
|
113
|
+
$input.focus();
|
114
|
+
$input.addEventListener('keyup', swal.resetInputError);
|
115
|
+
}, 400);
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
/*
|
121
|
+
* Custom image
|
122
|
+
*/
|
123
|
+
if (params.imageUrl) {
|
124
|
+
let $customIcon = modal.querySelector('.sa-icon.sa-custom');
|
125
|
+
|
126
|
+
$customIcon.style.backgroundImage = 'url(' + params.imageUrl + ')';
|
127
|
+
show($customIcon);
|
128
|
+
|
129
|
+
let _imgWidth = 80;
|
130
|
+
let _imgHeight = 80;
|
131
|
+
|
132
|
+
if (params.imageSize) {
|
133
|
+
let dimensions = params.imageSize.toString().split('x');
|
134
|
+
let imgWidth = dimensions[0];
|
135
|
+
let imgHeight = dimensions[1];
|
136
|
+
|
137
|
+
if (!imgWidth || !imgHeight) {
|
138
|
+
logStr('Parameter imageSize expects value with format WIDTHxHEIGHT, got ' + params.imageSize);
|
139
|
+
} else {
|
140
|
+
_imgWidth = imgWidth;
|
141
|
+
_imgHeight = imgHeight;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
$customIcon.setAttribute('style', $customIcon.getAttribute('style') + 'width:' + _imgWidth + 'px; height:' + _imgHeight + 'px');
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* Show cancel button?
|
150
|
+
*/
|
151
|
+
modal.setAttribute('data-has-cancel-button', params.showCancelButton);
|
152
|
+
if (params.showCancelButton) {
|
153
|
+
$cancelBtn.style.display = 'inline-block';
|
154
|
+
} else {
|
155
|
+
hide($cancelBtn);
|
156
|
+
}
|
157
|
+
|
158
|
+
/*
|
159
|
+
* Show confirm button?
|
160
|
+
*/
|
161
|
+
modal.setAttribute('data-has-confirm-button', params.showConfirmButton);
|
162
|
+
if (params.showConfirmButton) {
|
163
|
+
$confirmBtn.style.display = 'inline-block';
|
164
|
+
} else {
|
165
|
+
hide($confirmBtn);
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* Custom text on cancel/confirm buttons
|
170
|
+
*/
|
171
|
+
if (params.cancelButtonText) {
|
172
|
+
$cancelBtn.innerHTML = escapeHtml(params.cancelButtonText);
|
173
|
+
}
|
174
|
+
if (params.confirmButtonText) {
|
175
|
+
$confirmBtn.innerHTML = escapeHtml(params.confirmButtonText);
|
176
|
+
}
|
177
|
+
|
178
|
+
/*
|
179
|
+
* Custom color on confirm button
|
180
|
+
*/
|
181
|
+
if (params.confirmButtonColor) {
|
182
|
+
// Set confirm button to selected background color
|
183
|
+
$confirmBtn.style.backgroundColor = params.confirmButtonColor;
|
184
|
+
|
185
|
+
// Set the confirm button color to the loading ring
|
186
|
+
$confirmBtn.style.borderLeftColor = params.confirmLoadingButtonColor;
|
187
|
+
$confirmBtn.style.borderRightColor = params.confirmLoadingButtonColor;
|
188
|
+
|
189
|
+
// Set box-shadow to default focused button
|
190
|
+
setFocusStyle($confirmBtn, params.confirmButtonColor);
|
191
|
+
}
|
192
|
+
|
193
|
+
/*
|
194
|
+
* Allow outside click
|
195
|
+
*/
|
196
|
+
modal.setAttribute('data-allow-outside-click', params.allowOutsideClick);
|
197
|
+
|
198
|
+
/*
|
199
|
+
* Callback function
|
200
|
+
*/
|
201
|
+
var hasDoneFunction = params.doneFunction ? true : false;
|
202
|
+
modal.setAttribute('data-has-done-function', hasDoneFunction);
|
203
|
+
|
204
|
+
/*
|
205
|
+
* Animation
|
206
|
+
*/
|
207
|
+
if (!params.animation) {
|
208
|
+
modal.setAttribute('data-animation', 'none');
|
209
|
+
} else if (typeof params.animation === 'string') {
|
210
|
+
modal.setAttribute('data-animation', params.animation); // Custom animation
|
211
|
+
} else {
|
212
|
+
modal.setAttribute('data-animation', 'pop');
|
213
|
+
}
|
214
|
+
|
215
|
+
/*
|
216
|
+
* Timer
|
217
|
+
*/
|
218
|
+
modal.setAttribute('data-timer', params.timer);
|
219
|
+
};
|
220
|
+
|
221
|
+
export default setParameters;
|
@@ -0,0 +1,71 @@
|
|
1
|
+
/*
|
2
|
+
* Allow user to pass their own params
|
3
|
+
*/
|
4
|
+
var extend = function(a, b) {
|
5
|
+
for (var key in b) {
|
6
|
+
if (b.hasOwnProperty(key)) {
|
7
|
+
a[key] = b[key];
|
8
|
+
}
|
9
|
+
}
|
10
|
+
return a;
|
11
|
+
};
|
12
|
+
|
13
|
+
/*
|
14
|
+
* Convert HEX codes to RGB values (#000000 -> rgb(0,0,0))
|
15
|
+
*/
|
16
|
+
var hexToRgb = function(hex) {
|
17
|
+
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
18
|
+
return result ? parseInt(result[1], 16) + ', ' + parseInt(result[2], 16) + ', ' + parseInt(result[3], 16) : null;
|
19
|
+
};
|
20
|
+
|
21
|
+
/*
|
22
|
+
* Check if the user is using Internet Explorer 8 (for fallbacks)
|
23
|
+
*/
|
24
|
+
var isIE8 = function() {
|
25
|
+
return (window.attachEvent && !window.addEventListener);
|
26
|
+
};
|
27
|
+
|
28
|
+
/*
|
29
|
+
* IE compatible logging for developers
|
30
|
+
*/
|
31
|
+
var logStr = function(string) {
|
32
|
+
if (window.console) {
|
33
|
+
// IE...
|
34
|
+
window.console.log('SweetAlert: ' + string);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
/*
|
39
|
+
* Set hover, active and focus-states for buttons
|
40
|
+
* (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color)
|
41
|
+
*/
|
42
|
+
var colorLuminance = function(hex, lum) {
|
43
|
+
// Validate hex string
|
44
|
+
hex = String(hex).replace(/[^0-9a-f]/gi, '');
|
45
|
+
if (hex.length < 6) {
|
46
|
+
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
47
|
+
}
|
48
|
+
lum = lum || 0;
|
49
|
+
|
50
|
+
// Convert to decimal and change luminosity
|
51
|
+
var rgb = '#';
|
52
|
+
var c;
|
53
|
+
var i;
|
54
|
+
|
55
|
+
for (i = 0; i < 3; i++) {
|
56
|
+
c = parseInt(hex.substr(i * 2, 2), 16);
|
57
|
+
c = Math.round(Math.min(Math.max(0, c + c * lum), 255)).toString(16);
|
58
|
+
rgb += ('00' + c).substr(c.length);
|
59
|
+
}
|
60
|
+
|
61
|
+
return rgb;
|
62
|
+
};
|
63
|
+
|
64
|
+
|
65
|
+
export {
|
66
|
+
extend,
|
67
|
+
hexToRgb,
|
68
|
+
isIE8,
|
69
|
+
logStr,
|
70
|
+
colorLuminance
|
71
|
+
};
|
@@ -0,0 +1,311 @@
|
|
1
|
+
// SweetAlert
|
2
|
+
// 2014-2015 (c) - Tristan Edwards
|
3
|
+
// github.com/t4t5/sweetalert
|
4
|
+
|
5
|
+
/*
|
6
|
+
* jQuery-like functions for manipulating the DOM
|
7
|
+
*/
|
8
|
+
import {
|
9
|
+
hasClass, addClass, removeClass,
|
10
|
+
escapeHtml,
|
11
|
+
_show, show, _hide, hide,
|
12
|
+
isDescendant,
|
13
|
+
getTopMargin,
|
14
|
+
fadeIn, fadeOut,
|
15
|
+
fireClick,
|
16
|
+
stopEventPropagation
|
17
|
+
} from './modules/handle-dom';
|
18
|
+
|
19
|
+
/*
|
20
|
+
* Handy utilities
|
21
|
+
*/
|
22
|
+
import {
|
23
|
+
extend,
|
24
|
+
hexToRgb,
|
25
|
+
isIE8,
|
26
|
+
logStr,
|
27
|
+
colorLuminance
|
28
|
+
} from './modules/utils';
|
29
|
+
|
30
|
+
/*
|
31
|
+
* Handle sweetAlert's DOM elements
|
32
|
+
*/
|
33
|
+
import {
|
34
|
+
sweetAlertInitialize,
|
35
|
+
getModal,
|
36
|
+
getOverlay,
|
37
|
+
getInput,
|
38
|
+
setFocusStyle,
|
39
|
+
openModal,
|
40
|
+
resetInput,
|
41
|
+
fixVerticalPosition
|
42
|
+
} from './modules/handle-swal-dom';
|
43
|
+
|
44
|
+
|
45
|
+
// Handle button events and keyboard events
|
46
|
+
import { handleButton, handleConfirm, handleCancel } from './modules/handle-click';
|
47
|
+
import handleKeyDown from './modules/handle-key';
|
48
|
+
|
49
|
+
|
50
|
+
// Default values
|
51
|
+
import defaultParams from './modules/default-params';
|
52
|
+
import setParameters from './modules/set-params';
|
53
|
+
|
54
|
+
/*
|
55
|
+
* Remember state in cases where opening and handling a modal will fiddle with it.
|
56
|
+
* (We also use window.previousActiveElement as a global variable)
|
57
|
+
*/
|
58
|
+
var previousWindowKeyDown;
|
59
|
+
var lastFocusedButton;
|
60
|
+
|
61
|
+
|
62
|
+
/*
|
63
|
+
* Global sweetAlert function
|
64
|
+
* (this is what the user calls)
|
65
|
+
*/
|
66
|
+
var sweetAlert, swal;
|
67
|
+
|
68
|
+
sweetAlert = swal = function() {
|
69
|
+
var customizations = arguments[0];
|
70
|
+
|
71
|
+
addClass(document.body, 'stop-scrolling');
|
72
|
+
resetInput();
|
73
|
+
|
74
|
+
/*
|
75
|
+
* Use argument if defined or default value from params object otherwise.
|
76
|
+
* Supports the case where a default value is boolean true and should be
|
77
|
+
* overridden by a corresponding explicit argument which is boolean false.
|
78
|
+
*/
|
79
|
+
function argumentOrDefault(key) {
|
80
|
+
var args = customizations;
|
81
|
+
return (args[key] === undefined) ? defaultParams[key] : args[key];
|
82
|
+
}
|
83
|
+
|
84
|
+
if (customizations === undefined) {
|
85
|
+
logStr('SweetAlert expects at least 1 attribute!');
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
|
89
|
+
var params = extend({}, defaultParams);
|
90
|
+
|
91
|
+
switch (typeof customizations) {
|
92
|
+
|
93
|
+
// Ex: swal("Hello", "Just testing", "info");
|
94
|
+
case 'string':
|
95
|
+
params.title = customizations;
|
96
|
+
params.text = arguments[1] || '';
|
97
|
+
params.type = arguments[2] || '';
|
98
|
+
break;
|
99
|
+
|
100
|
+
// Ex: swal({ title:"Hello", text: "Just testing", type: "info" });
|
101
|
+
case 'object':
|
102
|
+
if (customizations.title === undefined) {
|
103
|
+
logStr('Missing "title" argument!');
|
104
|
+
return false;
|
105
|
+
}
|
106
|
+
|
107
|
+
params.title = customizations.title;
|
108
|
+
|
109
|
+
for (let customName in defaultParams) {
|
110
|
+
params[customName] = argumentOrDefault(customName);
|
111
|
+
}
|
112
|
+
|
113
|
+
// Show "Confirm" instead of "OK" if cancel button is visible
|
114
|
+
params.confirmButtonText = params.showCancelButton ? 'Confirm' : defaultParams.confirmButtonText;
|
115
|
+
params.confirmButtonText = argumentOrDefault('confirmButtonText');
|
116
|
+
|
117
|
+
// Callback function when clicking on "OK"/"Cancel"
|
118
|
+
params.doneFunction = arguments[1] || null;
|
119
|
+
|
120
|
+
break;
|
121
|
+
|
122
|
+
default:
|
123
|
+
logStr('Unexpected type of argument! Expected "string" or "object", got ' + typeof customizations);
|
124
|
+
return false;
|
125
|
+
|
126
|
+
}
|
127
|
+
|
128
|
+
setParameters(params);
|
129
|
+
fixVerticalPosition();
|
130
|
+
openModal(arguments[1]);
|
131
|
+
|
132
|
+
// Modal interactions
|
133
|
+
var modal = getModal();
|
134
|
+
|
135
|
+
|
136
|
+
/*
|
137
|
+
* Make sure all modal buttons respond to all events
|
138
|
+
*/
|
139
|
+
var $buttons = modal.querySelectorAll('button');
|
140
|
+
var buttonEvents = ['onclick', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup', 'onfocus'];
|
141
|
+
var onButtonEvent = (e) => handleButton(e, params, modal);
|
142
|
+
|
143
|
+
for (let btnIndex = 0; btnIndex < $buttons.length; btnIndex++) {
|
144
|
+
for (let evtIndex = 0; evtIndex < buttonEvents.length; evtIndex++) {
|
145
|
+
let btnEvt = buttonEvents[evtIndex];
|
146
|
+
$buttons[btnIndex][btnEvt] = onButtonEvent;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
// Clicking outside the modal dismisses it (if allowed by user)
|
151
|
+
getOverlay().onclick = onButtonEvent;
|
152
|
+
|
153
|
+
previousWindowKeyDown = window.onkeydown;
|
154
|
+
|
155
|
+
var onKeyEvent = (e) => handleKeyDown(e, params, modal);
|
156
|
+
window.onkeydown = onKeyEvent;
|
157
|
+
|
158
|
+
window.onfocus = function () {
|
159
|
+
// When the user has focused away and focused back from the whole window.
|
160
|
+
setTimeout(function () {
|
161
|
+
// Put in a timeout to jump out of the event sequence.
|
162
|
+
// Calling focus() in the event sequence confuses things.
|
163
|
+
if (lastFocusedButton !== undefined) {
|
164
|
+
lastFocusedButton.focus();
|
165
|
+
lastFocusedButton = undefined;
|
166
|
+
}
|
167
|
+
}, 0);
|
168
|
+
};
|
169
|
+
|
170
|
+
// Show alert with enabled buttons always
|
171
|
+
swal.enableButtons();
|
172
|
+
};
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
/*
|
177
|
+
* Set default params for each popup
|
178
|
+
* @param {Object} userParams
|
179
|
+
*/
|
180
|
+
sweetAlert.setDefaults = swal.setDefaults = function(userParams) {
|
181
|
+
if (!userParams) {
|
182
|
+
throw new Error('userParams is required');
|
183
|
+
}
|
184
|
+
if (typeof userParams !== 'object') {
|
185
|
+
throw new Error('userParams has to be a object');
|
186
|
+
}
|
187
|
+
|
188
|
+
extend(defaultParams, userParams);
|
189
|
+
};
|
190
|
+
|
191
|
+
|
192
|
+
/*
|
193
|
+
* Animation when closing modal
|
194
|
+
*/
|
195
|
+
sweetAlert.close = swal.close = function() {
|
196
|
+
var modal = getModal();
|
197
|
+
|
198
|
+
fadeOut(getOverlay(), 5);
|
199
|
+
fadeOut(modal, 5);
|
200
|
+
removeClass(modal, 'showSweetAlert');
|
201
|
+
addClass(modal, 'hideSweetAlert');
|
202
|
+
removeClass(modal, 'visible');
|
203
|
+
|
204
|
+
/*
|
205
|
+
* Reset icon animations
|
206
|
+
*/
|
207
|
+
var $successIcon = modal.querySelector('.sa-icon.sa-success');
|
208
|
+
removeClass($successIcon, 'animate');
|
209
|
+
removeClass($successIcon.querySelector('.sa-tip'), 'animateSuccessTip');
|
210
|
+
removeClass($successIcon.querySelector('.sa-long'), 'animateSuccessLong');
|
211
|
+
|
212
|
+
var $errorIcon = modal.querySelector('.sa-icon.sa-error');
|
213
|
+
removeClass($errorIcon, 'animateErrorIcon');
|
214
|
+
removeClass($errorIcon.querySelector('.sa-x-mark'), 'animateXMark');
|
215
|
+
|
216
|
+
var $warningIcon = modal.querySelector('.sa-icon.sa-warning');
|
217
|
+
removeClass($warningIcon, 'pulseWarning');
|
218
|
+
removeClass($warningIcon.querySelector('.sa-body'), 'pulseWarningIns');
|
219
|
+
removeClass($warningIcon.querySelector('.sa-dot'), 'pulseWarningIns');
|
220
|
+
|
221
|
+
// Reset custom class (delay so that UI changes aren't visible)
|
222
|
+
setTimeout(function() {
|
223
|
+
var customClass = modal.getAttribute('data-custom-class');
|
224
|
+
removeClass(modal, customClass);
|
225
|
+
}, 300);
|
226
|
+
|
227
|
+
// Make page scrollable again
|
228
|
+
removeClass(document.body, 'stop-scrolling');
|
229
|
+
|
230
|
+
// Reset the page to its previous state
|
231
|
+
window.onkeydown = previousWindowKeyDown;
|
232
|
+
if (window.previousActiveElement) {
|
233
|
+
window.previousActiveElement.focus();
|
234
|
+
}
|
235
|
+
lastFocusedButton = undefined;
|
236
|
+
clearTimeout(modal.timeout);
|
237
|
+
|
238
|
+
return true;
|
239
|
+
};
|
240
|
+
|
241
|
+
|
242
|
+
/*
|
243
|
+
* Validation of the input field is done by user
|
244
|
+
* If something is wrong => call showInputError with errorMessage
|
245
|
+
*/
|
246
|
+
sweetAlert.showInputError = swal.showInputError = function(errorMessage) {
|
247
|
+
var modal = getModal();
|
248
|
+
|
249
|
+
var $errorIcon = modal.querySelector('.sa-input-error');
|
250
|
+
addClass($errorIcon, 'show');
|
251
|
+
|
252
|
+
var $errorContainer = modal.querySelector('.sa-error-container');
|
253
|
+
addClass($errorContainer, 'show');
|
254
|
+
|
255
|
+
$errorContainer.querySelector('p').innerHTML = errorMessage;
|
256
|
+
|
257
|
+
setTimeout(function() {
|
258
|
+
sweetAlert.enableButtons();
|
259
|
+
}, 1);
|
260
|
+
|
261
|
+
modal.querySelector('input').focus();
|
262
|
+
};
|
263
|
+
|
264
|
+
|
265
|
+
/*
|
266
|
+
* Reset input error DOM elements
|
267
|
+
*/
|
268
|
+
sweetAlert.resetInputError = swal.resetInputError = function(event) {
|
269
|
+
// If press enter => ignore
|
270
|
+
if (event && event.keyCode === 13) {
|
271
|
+
return false;
|
272
|
+
}
|
273
|
+
|
274
|
+
var $modal = getModal();
|
275
|
+
|
276
|
+
var $errorIcon = $modal.querySelector('.sa-input-error');
|
277
|
+
removeClass($errorIcon, 'show');
|
278
|
+
|
279
|
+
var $errorContainer = $modal.querySelector('.sa-error-container');
|
280
|
+
removeClass($errorContainer, 'show');
|
281
|
+
};
|
282
|
+
|
283
|
+
/*
|
284
|
+
* Disable confirm and cancel buttons
|
285
|
+
*/
|
286
|
+
sweetAlert.disableButtons = swal.disableButtons = function(event) {
|
287
|
+
var modal = getModal();
|
288
|
+
var $confirmButton = modal.querySelector('button.confirm');
|
289
|
+
var $cancelButton = modal.querySelector('button.cancel');
|
290
|
+
$confirmButton.disabled = true;
|
291
|
+
$cancelButton.disabled = true;
|
292
|
+
};
|
293
|
+
|
294
|
+
/*
|
295
|
+
* Enable confirm and cancel buttons
|
296
|
+
*/
|
297
|
+
sweetAlert.enableButtons = swal.enableButtons = function(event) {
|
298
|
+
var modal = getModal();
|
299
|
+
var $confirmButton = modal.querySelector('button.confirm');
|
300
|
+
var $cancelButton = modal.querySelector('button.cancel');
|
301
|
+
$confirmButton.disabled = false;
|
302
|
+
$cancelButton.disabled = false;
|
303
|
+
};
|
304
|
+
|
305
|
+
if (typeof window !== 'undefined') {
|
306
|
+
// The 'handle-click' module requires
|
307
|
+
// that 'sweetAlert' was set as global.
|
308
|
+
window.sweetAlert = window.swal = sweetAlert;
|
309
|
+
} else {
|
310
|
+
logStr('SweetAlert is a frontend module!');
|
311
|
+
}
|