fomantic-ui-sass 2.9.0 → 2.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/fonts/semantic-ui/Lato-Bold.woff +0 -0
  3. data/app/assets/fonts/semantic-ui/Lato-Bold.woff2 +0 -0
  4. data/app/assets/fonts/semantic-ui/Lato-BoldItalic.woff +0 -0
  5. data/app/assets/fonts/semantic-ui/Lato-BoldItalic.woff2 +0 -0
  6. data/app/assets/fonts/semantic-ui/Lato-Italic.woff +0 -0
  7. data/app/assets/fonts/semantic-ui/Lato-Italic.woff2 +0 -0
  8. data/app/assets/fonts/semantic-ui/Lato-Regular.woff +0 -0
  9. data/app/assets/fonts/semantic-ui/Lato-Regular.woff2 +0 -0
  10. data/app/assets/fonts/semantic-ui/LatoLatin-Bold.woff +0 -0
  11. data/app/assets/fonts/semantic-ui/LatoLatin-Bold.woff2 +0 -0
  12. data/app/assets/fonts/semantic-ui/LatoLatin-BoldItalic.woff +0 -0
  13. data/app/assets/fonts/semantic-ui/LatoLatin-BoldItalic.woff2 +0 -0
  14. data/app/assets/fonts/semantic-ui/LatoLatin-Italic.woff +0 -0
  15. data/app/assets/fonts/semantic-ui/LatoLatin-Italic.woff2 +0 -0
  16. data/app/assets/fonts/semantic-ui/LatoLatin-Regular.woff +0 -0
  17. data/app/assets/fonts/semantic-ui/LatoLatin-Regular.woff2 +0 -0
  18. data/app/assets/fonts/semantic-ui/brand-icons.woff +0 -0
  19. data/app/assets/fonts/semantic-ui/brand-icons.woff2 +0 -0
  20. data/app/assets/fonts/semantic-ui/icons.woff +0 -0
  21. data/app/assets/fonts/semantic-ui/icons.woff2 +0 -0
  22. data/app/assets/fonts/semantic-ui/outline-icons.woff +0 -0
  23. data/app/assets/fonts/semantic-ui/outline-icons.woff2 +0 -0
  24. data/app/assets/javascripts/semantic-ui/accordion.js +569 -596
  25. data/app/assets/javascripts/semantic-ui/api.js +1158 -1180
  26. data/app/assets/javascripts/semantic-ui/calendar.js +1935 -1810
  27. data/app/assets/javascripts/semantic-ui/checkbox.js +843 -842
  28. data/app/assets/javascripts/semantic-ui/dimmer.js +707 -738
  29. data/app/assets/javascripts/semantic-ui/dropdown.js +4196 -4237
  30. data/app/assets/javascripts/semantic-ui/embed.js +646 -676
  31. data/app/assets/javascripts/semantic-ui/flyout.js +1515 -1466
  32. data/app/assets/javascripts/semantic-ui/form.js +2023 -2005
  33. data/app/assets/javascripts/semantic-ui/modal.js +1545 -1487
  34. data/app/assets/javascripts/semantic-ui/nag.js +521 -527
  35. data/app/assets/javascripts/semantic-ui/popup.js +1457 -1457
  36. data/app/assets/javascripts/semantic-ui/progress.js +970 -998
  37. data/app/assets/javascripts/semantic-ui/rating.js +508 -524
  38. data/app/assets/javascripts/semantic-ui/search.js +1521 -1535
  39. data/app/assets/javascripts/semantic-ui/shape.js +784 -811
  40. data/app/assets/javascripts/semantic-ui/sidebar.js +1062 -1100
  41. data/app/assets/javascripts/semantic-ui/site.js +437 -477
  42. data/app/assets/javascripts/semantic-ui/slider.js +1311 -1312
  43. data/app/assets/javascripts/semantic-ui/state.js +639 -658
  44. data/app/assets/javascripts/semantic-ui/sticky.js +848 -902
  45. data/app/assets/javascripts/semantic-ui/tab.js +903 -967
  46. data/app/assets/javascripts/semantic-ui/toast.js +911 -885
  47. data/app/assets/javascripts/semantic-ui/transition.js +1049 -1078
  48. data/app/assets/javascripts/semantic-ui/visibility.js +1214 -1246
  49. data/app/assets/stylesheets/semantic-ui/collections/_breadcrumb.scss +7 -7
  50. data/app/assets/stylesheets/semantic-ui/collections/_form.scss +246 -341
  51. data/app/assets/stylesheets/semantic-ui/collections/_grid.scss +185 -331
  52. data/app/assets/stylesheets/semantic-ui/collections/_menu.scss +272 -433
  53. data/app/assets/stylesheets/semantic-ui/collections/_message.scss +127 -199
  54. data/app/assets/stylesheets/semantic-ui/collections/_table.scss +549 -776
  55. data/app/assets/stylesheets/semantic-ui/elements/_button.scss +711 -1123
  56. data/app/assets/stylesheets/semantic-ui/elements/_container.scss +9 -8
  57. data/app/assets/stylesheets/semantic-ui/elements/_divider.scss +45 -63
  58. data/app/assets/stylesheets/semantic-ui/elements/_emoji.scss +3556 -3556
  59. data/app/assets/stylesheets/semantic-ui/elements/_flag.scss +272 -270
  60. data/app/assets/stylesheets/semantic-ui/elements/_header.scss +120 -144
  61. data/app/assets/stylesheets/semantic-ui/elements/_icon.scss +667 -747
  62. data/app/assets/stylesheets/semantic-ui/elements/_image.scss +41 -65
  63. data/app/assets/stylesheets/semantic-ui/elements/_input.scss +358 -276
  64. data/app/assets/stylesheets/semantic-ui/elements/_label.scss +361 -412
  65. data/app/assets/stylesheets/semantic-ui/elements/_list.scss +51 -72
  66. data/app/assets/stylesheets/semantic-ui/elements/_loader.scss +69 -157
  67. data/app/assets/stylesheets/semantic-ui/elements/_placeholder.scss +24 -44
  68. data/app/assets/stylesheets/semantic-ui/elements/_rail.scss +17 -22
  69. data/app/assets/stylesheets/semantic-ui/elements/_reveal.scss +46 -85
  70. data/app/assets/stylesheets/semantic-ui/elements/_segment.scss +150 -226
  71. data/app/assets/stylesheets/semantic-ui/elements/_step.scss +79 -152
  72. data/app/assets/stylesheets/semantic-ui/elements/_text.scss +33 -33
  73. data/app/assets/stylesheets/semantic-ui/globals/_reset.scss +10 -15
  74. data/app/assets/stylesheets/semantic-ui/globals/_site.scss +30 -43
  75. data/app/assets/stylesheets/semantic-ui/modules/_accordion.scss +37 -55
  76. data/app/assets/stylesheets/semantic-ui/modules/_calendar.scss +26 -29
  77. data/app/assets/stylesheets/semantic-ui/modules/_checkbox.scss +122 -193
  78. data/app/assets/stylesheets/semantic-ui/modules/_dimmer.scss +55 -174
  79. data/app/assets/stylesheets/semantic-ui/modules/_dropdown.scss +254 -388
  80. data/app/assets/stylesheets/semantic-ui/modules/_embed.scss +20 -31
  81. data/app/assets/stylesheets/semantic-ui/modules/_flyout.scss +97 -143
  82. data/app/assets/stylesheets/semantic-ui/modules/_modal.scss +122 -156
  83. data/app/assets/stylesheets/semantic-ui/modules/_nag.scss +55 -65
  84. data/app/assets/stylesheets/semantic-ui/modules/_popup.scss +426 -204
  85. data/app/assets/stylesheets/semantic-ui/modules/_progress.scss +108 -213
  86. data/app/assets/stylesheets/semantic-ui/modules/_rating.scss +83 -124
  87. data/app/assets/stylesheets/semantic-ui/modules/_search.scss +71 -100
  88. data/app/assets/stylesheets/semantic-ui/modules/_shape.scss +16 -32
  89. data/app/assets/stylesheets/semantic-ui/modules/_sidebar.scss +105 -208
  90. data/app/assets/stylesheets/semantic-ui/modules/_slider.scss +93 -121
  91. data/app/assets/stylesheets/semantic-ui/modules/_sticky.scss +3 -7
  92. data/app/assets/stylesheets/semantic-ui/modules/_tab.scss +12 -16
  93. data/app/assets/stylesheets/semantic-ui/modules/_toast.scss +71 -149
  94. data/app/assets/stylesheets/semantic-ui/modules/_transition.scss +371 -1282
  95. data/app/assets/stylesheets/semantic-ui/views/_ad.scss +36 -47
  96. data/app/assets/stylesheets/semantic-ui/views/_card.scss +221 -367
  97. data/app/assets/stylesheets/semantic-ui/views/_comment.scss +43 -61
  98. data/app/assets/stylesheets/semantic-ui/views/_feed.scss +37 -59
  99. data/app/assets/stylesheets/semantic-ui/views/_item.scss +86 -133
  100. data/app/assets/stylesheets/semantic-ui/views/_statistic.scss +77 -118
  101. data/lib/fomantic/ui/sass/version.rb +2 -2
  102. data/tasks/converter.rb +1 -1
  103. metadata +17 -1
@@ -1,1556 +1,1614 @@
1
1
  /*!
2
2
  * # Fomantic-UI - Modal
3
- * http://github.com/fomantic/Fomantic-UI/
3
+ * https://github.com/fomantic/Fomantic-UI/
4
4
  *
5
5
  *
6
6
  * Released under the MIT license
7
- * http://opensource.org/licenses/MIT
7
+ * https://opensource.org/licenses/MIT
8
8
  *
9
9
  */
10
10
 
11
- ;(function ($, window, document, undefined) {
12
-
13
- 'use strict';
14
-
15
- $.isFunction = $.isFunction || function(obj) {
16
- return typeof obj === "function" && typeof obj.nodeType !== "number";
17
- };
18
-
19
- window = (typeof window != 'undefined' && window.Math == Math)
20
- ? window
21
- : (typeof self != 'undefined' && self.Math == Math)
22
- ? self
23
- : Function('return this')()
24
- ;
25
-
26
- $.modal = $.fn.modal = function(parameters) {
27
- var
28
- $allModules = $(this),
29
- $window = $(window),
30
- $document = $(document),
31
- $body = $('body'),
32
-
33
- moduleSelector = $allModules.selector || '',
34
-
35
- time = new Date().getTime(),
36
- performance = [],
37
-
38
- query = arguments[0],
39
- methodInvoked = (typeof query == 'string'),
40
- queryArguments = [].slice.call(arguments, 1),
41
-
42
- requestAnimationFrame = window.requestAnimationFrame
43
- || window.mozRequestAnimationFrame
44
- || window.webkitRequestAnimationFrame
45
- || window.msRequestAnimationFrame
46
- || function(callback) { setTimeout(callback, 0); },
47
-
48
- returnedValue
49
- ;
50
-
51
- $allModules
52
- .each(function() {
53
- var
54
- settings = ( $.isPlainObject(parameters) )
55
- ? $.extend(true, {}, $.fn.modal.settings, parameters)
56
- : $.extend({}, $.fn.modal.settings),
57
-
58
- selector = settings.selector,
59
- className = settings.className,
60
- namespace = settings.namespace,
61
- fields = settings.fields,
62
- error = settings.error,
63
-
64
- eventNamespace = '.' + namespace,
65
- moduleNamespace = 'module-' + namespace,
66
-
67
- $module = $(this),
68
- $context = [window,document].indexOf(settings.context) < 0 ? $document.find(settings.context) : $body,
69
- isBody = $context[0] === $body[0],
70
- $closeIcon = $module.find(selector.closeIcon),
71
- $inputs,
72
-
73
- $allModals,
74
- $otherModals,
75
- $focusedElement,
76
- $dimmable,
77
- $dimmer,
78
-
79
- isModalComponent = $module.hasClass('modal'),
80
-
81
- element = this,
82
- instance = isModalComponent ? $module.data(moduleNamespace) : undefined,
83
-
84
- ignoreRepeatedEvents = false,
85
-
86
- initialMouseDownInModal,
87
- initialMouseDownInScrollbar,
88
- initialBodyMargin = '',
89
- tempBodyMargin = '',
90
- keepScrollingClass = false,
91
- hadScrollbar = false,
92
-
93
- elementEventNamespace,
94
- id,
95
- observer,
96
- module
97
- ;
98
- module = {
99
-
100
- initialize: function() {
101
- module.create.id();
102
- if(!isModalComponent) {
103
- module.create.modal();
104
- if(!$.isFunction(settings.onHidden)) {
105
- settings.onHidden = function () {
106
- module.destroy();
107
- $module.remove();
108
- };
109
- }
110
- }
111
- $module.addClass(settings.class);
112
- if (settings.title !== '') {
113
- $module.find(selector.title).html(module.helpers.escape(settings.title, settings.preserveHTML)).addClass(settings.classTitle);
114
- }
115
- if (settings.content !== '') {
116
- $module.find(selector.content).html(module.helpers.escape(settings.content, settings.preserveHTML)).addClass(settings.classContent);
117
- }
118
- if(module.has.configActions()){
119
- var $actions = $module.find(selector.actions).addClass(settings.classActions);
120
- if ($actions.length === 0) {
121
- $actions = $('<div/>', {class: className.actions + ' ' + (settings.classActions || '')}).appendTo($module);
122
- } else {
123
- $actions.empty();
124
- }
125
- settings.actions.forEach(function (el) {
126
- var icon = el[fields.icon] ? '<i '+(el[fields.text] ? 'aria-hidden="true"' : '')+' class="' + module.helpers.deQuote(el[fields.icon]) + ' icon"></i>' : '',
127
- text = module.helpers.escape(el[fields.text] || '', settings.preserveHTML),
128
- cls = module.helpers.deQuote(el[fields.class] || ''),
129
- click = el[fields.click] && $.isFunction(el[fields.click]) ? el[fields.click] : function () {};
130
- $actions.append($('<button/>', {
131
- html: icon + text,
132
- 'aria-label': (el[fields.text] || el[fields.icon] || '').replace(/<[^>]+(>|$)/g,''),
133
- class: className.button + ' ' + cls,
134
- click: function () {
135
- var button = $(this);
136
- if (button.is(selector.approve) || button.is(selector.deny) || click.call(element, $module) === false) {
137
- return;
138
- }
139
- module.hide();
140
- }
141
- }));
142
- });
143
- }
144
- module.cache = {};
145
- module.verbose('Initializing dimmer', $context);
146
-
147
- module.create.dimmer();
148
-
149
- if ( settings.allowMultiple ) {
150
- module.create.innerDimmer();
151
- }
152
- if (!settings.centered){
153
- $module.addClass('top aligned');
154
- }
155
- module.refreshModals();
156
- module.bind.events();
157
- module.observeChanges();
158
- module.instantiate();
159
- if(settings.autoShow){
160
- module.show();
161
- }
162
- },
11
+ (function ($, window, document) {
12
+ 'use strict';
163
13
 
164
- instantiate: function() {
165
- module.verbose('Storing instance of modal');
166
- instance = module;
167
- $module
168
- .data(moduleNamespace, instance)
169
- ;
170
- },
14
+ function isFunction(obj) {
15
+ return typeof obj === 'function' && typeof obj.nodeType !== 'number';
16
+ }
171
17
 
172
- create: {
173
- modal: function() {
174
- $module = $('<div/>', {class: className.modal, role: 'dialog', 'aria-modal': true});
175
- if (settings.closeIcon) {
176
- $closeIcon = $('<i/>', {class: className.close, role: 'button', tabindex: 0, 'aria-label': settings.text.close})
177
- $module.append($closeIcon);
178
- }
179
- if (settings.title !== '') {
180
- var titleId = '_' + module.get.id() + 'title';
181
- $module.attr('aria-labelledby', titleId);
182
- $('<div/>', {class: className.title, id: titleId}).appendTo($module);
183
- }
184
- if (settings.content !== '') {
185
- var descId = '_' + module.get.id() + 'desc';
186
- $module.attr('aria-describedby', descId);
187
- $('<div/>', {class: className.content, id: descId}).appendTo($module);
188
- }
189
- if (module.has.configActions()) {
190
- $('<div/>', {class: className.actions}).appendTo($module);
191
- }
192
- $context.append($module);
193
- element = $module[0];
194
- },
195
- dimmer: function() {
18
+ window = window !== undefined && window.Math === Math
19
+ ? window
20
+ : globalThis;
21
+
22
+ $.fn.modal = function (parameters) {
23
+ var
24
+ $allModules = $(this),
25
+ $window = $(window),
26
+ $document = $(document),
27
+ $body = $('body'),
28
+
29
+ moduleSelector = $allModules.selector || '',
30
+
31
+ time = Date.now(),
32
+ performance = [],
33
+
34
+ query = arguments[0],
35
+ methodInvoked = typeof query === 'string',
36
+ queryArguments = [].slice.call(arguments, 1),
37
+
38
+ returnedValue
39
+ ;
40
+
41
+ $allModules.each(function () {
196
42
  var
197
- defaultSettings = {
198
- debug : settings.debug,
199
- dimmerName : 'modals'
200
- },
201
- dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
43
+ settings = $.isPlainObject(parameters)
44
+ ? $.extend(true, {}, $.fn.modal.settings, parameters)
45
+ : $.extend({}, $.fn.modal.settings),
46
+
47
+ selector = settings.selector,
48
+ className = settings.className,
49
+ namespace = settings.namespace,
50
+ fields = settings.fields,
51
+ error = settings.error,
52
+
53
+ eventNamespace = '.' + namespace,
54
+ moduleNamespace = 'module-' + namespace,
55
+
56
+ $module = $(this),
57
+ $context = [window, document].indexOf(settings.context) < 0 ? $document.find(settings.context) : $body,
58
+ isBody = $context[0] === $body[0],
59
+ $closeIcon = $module.find(selector.closeIcon),
60
+ $inputs,
61
+
62
+ $allModals,
63
+ $otherModals,
64
+ $focusedElement,
65
+ $dimmable,
66
+ $dimmer,
67
+
68
+ isModalComponent = $module.hasClass('modal'),
69
+
70
+ element = this,
71
+ instance = isModalComponent ? $module.data(moduleNamespace) : undefined,
72
+
73
+ ignoreRepeatedEvents = false,
74
+
75
+ initialMouseDownInModal,
76
+ initialMouseDownInScrollbar,
77
+ initialBodyMargin = '',
78
+ tempBodyMargin = '',
79
+ keepScrollingClass = false,
80
+ hadScrollbar = false,
81
+
82
+ elementEventNamespace,
83
+ id,
84
+ observer,
85
+ module
202
86
  ;
203
- if($.fn.dimmer === undefined) {
204
- module.error(error.dimmer);
205
- return;
206
- }
207
- module.debug('Creating dimmer');
208
- $dimmable = $context.dimmer(dimmerSettings);
209
- keepScrollingClass = module.is.scrolling();
210
- if(settings.detachable) {
211
- module.verbose('Modal is detachable, moving content into dimmer');
212
- $dimmable.dimmer('add content', $module);
213
- }
214
- else {
215
- module.set.undetached();
216
- }
217
- $dimmer = $dimmable.dimmer('get dimmer');
218
- },
219
- id: function() {
220
- id = (Math.random().toString(16) + '000000000').slice(2, 10);
221
- elementEventNamespace = '.' + id;
222
- module.verbose('Creating unique id for element', id);
223
- },
224
- innerDimmer: function() {
225
- if ( $module.find(selector.dimmer).length === 0 ) {
226
- $('<div/>', {class: className.innerDimmer}).prependTo($module);
227
- }
228
- }
229
- },
87
+ module = {
88
+
89
+ initialize: function () {
90
+ module.create.id();
91
+ if (!isModalComponent) {
92
+ module.create.modal();
93
+ if (!isFunction(settings.onHidden)) {
94
+ settings.onHidden = function () {
95
+ module.destroy();
96
+ $module.remove();
97
+ };
98
+ }
99
+ }
100
+ $module.addClass(settings.class);
101
+ if (settings.title !== '') {
102
+ $module.find(selector.title).html(module.helpers.escape(settings.title, settings.preserveHTML)).addClass(settings.classTitle);
103
+ }
104
+ if (settings.content !== '') {
105
+ $module.find(selector.content).html(module.helpers.escape(settings.content, settings.preserveHTML)).addClass(settings.classContent);
106
+ }
107
+ if (module.has.configActions()) {
108
+ var $actions = $module.find(selector.actions).addClass(settings.classActions);
109
+ if ($actions.length === 0) {
110
+ $actions = $('<div/>', { class: className.actions + ' ' + (settings.classActions || '') }).appendTo($module);
111
+ } else {
112
+ $actions.empty();
113
+ }
114
+ settings.actions.forEach(function (el) {
115
+ var
116
+ icon = el[fields.icon]
117
+ ? '<i ' + (el[fields.text] ? 'aria-hidden="true"' : '') + ' class="' + module.helpers.deQuote(el[fields.icon]) + ' icon"></i>'
118
+ : '',
119
+ text = module.helpers.escape(el[fields.text] || '', settings.preserveHTML),
120
+ cls = module.helpers.deQuote(el[fields.class] || ''),
121
+ click = el[fields.click] && isFunction(el[fields.click])
122
+ ? el[fields.click]
123
+ : function () {}
124
+ ;
125
+ $actions.append($('<button/>', {
126
+ html: icon + text,
127
+ 'aria-label': (el[fields.text] || el[fields.icon] || '').replace(/<[^>]+(>|$)/g, ''),
128
+ class: className.button + ' ' + cls,
129
+ on: {
130
+ click: function () {
131
+ var button = $(this);
132
+ if (button.is(selector.approve) || button.is(selector.deny) || click.call(element, $module) === false) {
133
+ return;
134
+ }
135
+ module.hide();
136
+ },
137
+ },
138
+ }));
139
+ });
140
+ }
141
+ module.cache = {};
142
+ module.verbose('Initializing dimmer', $context);
230
143
 
231
- destroy: function() {
232
- if (observer) {
233
- observer.disconnect();
234
- }
235
- module.verbose('Destroying previous modal');
236
- $module
237
- .removeData(moduleNamespace)
238
- .off(eventNamespace)
239
- ;
240
- $window.off(elementEventNamespace);
241
- $dimmer.off(elementEventNamespace);
242
- $closeIcon.off(elementEventNamespace);
243
- if($inputs) {
244
- $inputs.off(elementEventNamespace);
245
- }
246
- $context.dimmer('destroy');
247
- },
144
+ module.create.dimmer();
248
145
 
249
- observeChanges: function() {
250
- if('MutationObserver' in window) {
251
- observer = new MutationObserver(function(mutations) {
252
- if(settings.observeChanges) {
253
- module.debug('DOM tree modified, refreshing');
254
- module.refresh();
255
- }
256
- module.refreshInputs();
257
- });
258
- observer.observe(element, {
259
- childList : true,
260
- subtree : true
261
- });
262
- module.debug('Setting up mutation observer', observer);
263
- }
264
- },
146
+ if (settings.allowMultiple) {
147
+ module.create.innerDimmer();
148
+ }
149
+ if (!settings.centered) {
150
+ $module.addClass('top aligned');
151
+ }
152
+ module.refreshModals();
153
+ module.bind.events();
154
+ module.observeChanges();
155
+ module.instantiate();
156
+ if (settings.autoShow) {
157
+ module.show();
158
+ }
159
+ },
265
160
 
266
- refresh: function() {
267
- module.remove.scrolling();
268
- module.cacheSizes();
269
- if(!module.can.useFlex()) {
270
- module.set.modalOffset();
271
- }
272
- module.set.screenHeight();
273
- module.set.type();
274
- },
161
+ instantiate: function () {
162
+ module.verbose('Storing instance of modal');
163
+ instance = module;
164
+ $module
165
+ .data(moduleNamespace, instance)
166
+ ;
167
+ },
275
168
 
276
- refreshModals: function() {
277
- $otherModals = $module.siblings(selector.modal);
278
- $allModals = $otherModals.add($module);
279
- },
169
+ create: {
170
+ modal: function () {
171
+ $module = $('<div/>', { class: className.modal, role: 'dialog', 'aria-modal': true });
172
+ if (settings.closeIcon) {
173
+ $closeIcon = $('<i/>', {
174
+ class: className.close,
175
+ role: 'button',
176
+ tabindex: 0,
177
+ 'aria-label': settings.text.close,
178
+ });
179
+ $module.append($closeIcon);
180
+ }
181
+ if (settings.title !== '') {
182
+ var titleId = '_' + module.get.id() + 'title';
183
+ $module.attr('aria-labelledby', titleId);
184
+ $('<div/>', { class: className.title, id: titleId }).appendTo($module);
185
+ }
186
+ if (settings.content !== '') {
187
+ var descId = '_' + module.get.id() + 'desc';
188
+ $module.attr('aria-describedby', descId);
189
+ $('<div/>', { class: className.content, id: descId }).appendTo($module);
190
+ }
191
+ if (module.has.configActions()) {
192
+ $('<div/>', { class: className.actions }).appendTo($module);
193
+ }
194
+ $context.append($module);
195
+ element = $module[0];
196
+ },
197
+ dimmer: function () {
198
+ var
199
+ defaultSettings = {
200
+ debug: settings.debug,
201
+ dimmerName: 'modals',
202
+ },
203
+ dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
204
+ ;
205
+ if ($.fn.dimmer === undefined) {
206
+ module.error(error.dimmer);
207
+
208
+ return;
209
+ }
210
+ module.debug('Creating dimmer');
211
+ $dimmable = $context.dimmer(dimmerSettings);
212
+ keepScrollingClass = module.is.scrolling();
213
+ if (settings.detachable) {
214
+ module.verbose('Modal is detachable, moving content into dimmer');
215
+ $dimmable.dimmer('add content', $module);
216
+ } else {
217
+ module.set.undetached();
218
+ }
219
+ $dimmer = $dimmable.dimmer('get dimmer');
220
+ },
221
+ id: function () {
222
+ id = (Math.random().toString(16) + '000000000').slice(2, 10);
223
+ elementEventNamespace = '.' + id;
224
+ module.verbose('Creating unique id for element', id);
225
+ },
226
+ innerDimmer: function () {
227
+ if ($module.find(selector.dimmer).length === 0) {
228
+ $('<div/>', { class: className.innerDimmer }).prependTo($module);
229
+ }
230
+ },
231
+ },
280
232
 
281
- refreshInputs: function(){
282
- if($inputs){
283
- $inputs
284
- .off('keydown' + elementEventNamespace)
285
- ;
286
- }
287
- $inputs = $module.find('[tabindex], :input').filter(':visible').filter(function() {
288
- return $(this).closest('.disabled').length === 0;
289
- });
290
- $inputs.first()
291
- .on('keydown' + elementEventNamespace, module.event.inputKeyDown.first)
292
- ;
293
- $inputs.last()
294
- .on('keydown' + elementEventNamespace, module.event.inputKeyDown.last)
295
- ;
296
- },
233
+ destroy: function () {
234
+ if (observer) {
235
+ observer.disconnect();
236
+ }
237
+ module.verbose('Destroying previous modal');
238
+ $module
239
+ .removeData(moduleNamespace)
240
+ .off(eventNamespace)
241
+ ;
242
+ $window.off(elementEventNamespace);
243
+ $dimmer.off(elementEventNamespace);
244
+ $closeIcon.off(elementEventNamespace);
245
+ if ($inputs) {
246
+ $inputs.off(elementEventNamespace);
247
+ }
248
+ $context.dimmer('destroy');
249
+ },
297
250
 
298
- attachEvents: function(selector, event) {
299
- var
300
- $toggle = $(selector)
301
- ;
302
- event = $.isFunction(module[event])
303
- ? module[event]
304
- : module.toggle
305
- ;
306
- if($toggle.length > 0) {
307
- module.debug('Attaching modal events to element', selector, event);
308
- $toggle
309
- .off(eventNamespace)
310
- .on('click' + eventNamespace, event)
311
- ;
312
- }
313
- else {
314
- module.error(error.notFound, selector);
315
- }
316
- },
251
+ observeChanges: function () {
252
+ if ('MutationObserver' in window) {
253
+ observer = new MutationObserver(function (mutations) {
254
+ var collectNodes = function (parent) {
255
+ var nodes = [];
256
+ for (var c = 0, cl = parent.length; c < cl; c++) {
257
+ Array.prototype.push.apply(nodes, collectNodes(parent[c].childNodes));
258
+ nodes.push(parent[c]);
259
+ }
260
+
261
+ return nodes;
262
+ },
263
+ shouldRefresh = false,
264
+ shouldRefreshInputs = false
265
+ ;
266
+ mutations.every(function (mutation) {
267
+ if (mutation.type === 'attributes') {
268
+ if (mutation.attributeName === 'disabled' || $(mutation.target).find(':input').addBack(':input')) {
269
+ shouldRefreshInputs = true;
270
+ }
271
+ } else {
272
+ shouldRefresh = true;
273
+ // mutationobserver only provides the parent nodes
274
+ // so let's collect all childs as well to find nested inputs
275
+ var $addedInputs = $(collectNodes(mutation.addedNodes)).filter('a[href], [tabindex], :input:enabled').filter(':visible'),
276
+ $removedInputs = $(collectNodes(mutation.removedNodes)).filter('a[href], [tabindex], :input');
277
+ if ($addedInputs.length > 0 || $removedInputs.length > 0) {
278
+ shouldRefreshInputs = true;
279
+ }
280
+ }
281
+
282
+ return !shouldRefreshInputs;
283
+ });
284
+
285
+ if (shouldRefresh && settings.observeChanges) {
286
+ module.debug('DOM tree modified, refreshing');
287
+ module.refresh();
288
+ }
289
+ if (shouldRefreshInputs) {
290
+ module.refreshInputs();
291
+ }
292
+ });
293
+ observer.observe(element, {
294
+ attributeFilter: ['class', 'disabled'],
295
+ attributes: true,
296
+ childList: true,
297
+ subtree: true,
298
+ });
299
+ module.debug('Setting up mutation observer', observer);
300
+ }
301
+ },
317
302
 
318
- bind: {
319
- events: function() {
320
- module.verbose('Attaching events');
321
- $module
322
- .on('click' + eventNamespace, selector.close, module.event.close)
323
- .on('click' + eventNamespace, selector.approve, module.event.approve)
324
- .on('click' + eventNamespace, selector.deny, module.event.deny)
325
- ;
326
- $closeIcon
327
- .on('keyup' + elementEventNamespace, module.event.closeKeyUp)
328
- ;
329
- $window
330
- .on('resize' + elementEventNamespace, module.event.resize)
331
- ;
332
- },
333
- scrollLock: function() {
334
- // touch events default to passive, due to changes in chrome to optimize mobile perf
335
- $dimmable[0].addEventListener('touchmove', module.event.preventScroll, { passive: false });
336
- }
337
- },
303
+ refresh: function () {
304
+ module.remove.scrolling();
305
+ module.cacheSizes();
306
+ if (!module.can.useFlex()) {
307
+ module.set.modalOffset();
308
+ }
309
+ module.set.screenHeight();
310
+ module.set.type();
311
+ },
338
312
 
339
- unbind: {
340
- scrollLock: function() {
341
- $dimmable[0].removeEventListener('touchmove', module.event.preventScroll, { passive: false });
342
- }
343
- },
313
+ refreshModals: function () {
314
+ $otherModals = $module.siblings(selector.modal);
315
+ $allModals = $otherModals.add($module);
316
+ },
344
317
 
345
- get: {
346
- id: function() {
347
- return id;
348
- },
349
- element: function() {
350
- return $module;
351
- },
352
- settings: function() {
353
- return settings;
354
- }
355
- },
318
+ refreshInputs: function () {
319
+ if ($inputs) {
320
+ $inputs
321
+ .off('keydown' + elementEventNamespace)
322
+ ;
323
+ }
324
+ $inputs = $module.find('a[href], [tabindex], :input:enabled').filter(':visible').filter(function () {
325
+ return $(this).closest('.disabled').length === 0;
326
+ });
327
+ $module.removeAttr('tabindex');
328
+ if ($inputs.length === 0) {
329
+ $inputs = $module;
330
+ $module.attr('tabindex', -1);
331
+ }
332
+ $inputs.first()
333
+ .on('keydown' + elementEventNamespace, module.event.inputKeyDown.first)
334
+ ;
335
+ $inputs.last()
336
+ .on('keydown' + elementEventNamespace, module.event.inputKeyDown.last)
337
+ ;
338
+ if (settings.autofocus && $inputs.filter(':focus').length === 0) {
339
+ module.set.autofocus();
340
+ }
341
+ },
356
342
 
357
- event: {
358
- approve: function() {
359
- if(ignoreRepeatedEvents || settings.onApprove.call(element, $(this)) === false) {
360
- module.verbose('Approve callback returned false cancelling hide');
361
- return;
362
- }
363
- ignoreRepeatedEvents = true;
364
- module.hide(function() {
365
- ignoreRepeatedEvents = false;
366
- });
367
- },
368
- preventScroll: function(event) {
369
- if(event.target.className.indexOf('dimmer') !== -1) {
370
- event.preventDefault();
371
- }
372
- },
373
- deny: function() {
374
- if(ignoreRepeatedEvents || settings.onDeny.call(element, $(this)) === false) {
375
- module.verbose('Deny callback returned false cancelling hide');
376
- return;
377
- }
378
- ignoreRepeatedEvents = true;
379
- module.hide(function() {
380
- ignoreRepeatedEvents = false;
381
- });
382
- },
383
- close: function() {
384
- module.hide();
385
- },
386
- closeKeyUp: function(event){
387
- var
388
- keyCode = event.which
389
- ;
390
- if ((keyCode === settings.keys.enter || keyCode === settings.keys.space) && $module.hasClass(className.front)) {
391
- module.hide();
392
- }
393
- },
394
- inputKeyDown: {
395
- first: function(event) {
396
- var
397
- keyCode = event.which
398
- ;
399
- if (keyCode === settings.keys.tab && event.shiftKey) {
400
- $inputs.last().focus();
401
- event.preventDefault();
402
- }
403
- },
404
- last: function(event) {
405
- var
406
- keyCode = event.which
407
- ;
408
- if (keyCode === settings.keys.tab && !event.shiftKey) {
409
- $inputs.first().focus();
410
- event.preventDefault();
411
- }
412
- }
413
- },
414
- mousedown: function(event) {
415
- var
416
- $target = $(event.target),
417
- isRtl = module.is.rtl()
418
- ;
419
- initialMouseDownInModal = ($target.closest(selector.modal).length > 0);
420
- if(initialMouseDownInModal) {
421
- module.verbose('Mouse down event registered inside the modal');
422
- }
423
- initialMouseDownInScrollbar = module.is.scrolling() && ((!isRtl && $window.outerWidth() - settings.scrollbarWidth <= event.clientX) || (isRtl && settings.scrollbarWidth >= event.clientX));
424
- if(initialMouseDownInScrollbar) {
425
- module.verbose('Mouse down event registered inside the scrollbar');
426
- }
427
- },
428
- mouseup: function(event) {
429
- if(!settings.closable) {
430
- module.verbose('Dimmer clicked but closable setting is disabled');
431
- return;
432
- }
433
- if(initialMouseDownInModal) {
434
- module.debug('Dimmer clicked but mouse down was initially registered inside the modal');
435
- return;
436
- }
437
- if(initialMouseDownInScrollbar){
438
- module.debug('Dimmer clicked but mouse down was initially registered inside the scrollbar');
439
- return;
440
- }
441
- var
442
- $target = $(event.target),
443
- isInModal = ($target.closest(selector.modal).length > 0),
444
- isInDOM = $.contains(document.documentElement, event.target)
445
- ;
446
- if(!isInModal && isInDOM && module.is.active() && $module.hasClass(className.front) ) {
447
- module.debug('Dimmer clicked, hiding all modals');
448
- if(settings.allowMultiple) {
449
- if(!module.hideAll()) {
450
- return;
451
- }
452
- }
453
- else if(!module.hide()){
454
- return;
455
- }
456
- module.remove.clickaway();
457
- }
458
- },
459
- debounce: function(method, delay) {
460
- clearTimeout(module.timer);
461
- module.timer = setTimeout(method, delay);
462
- },
463
- keyboard: function(event) {
464
- var
465
- keyCode = event.which
466
- ;
467
- if(keyCode === settings.keys.escape) {
468
- if(settings.closable) {
469
- module.debug('Escape key pressed hiding modal');
470
- if ( $module.hasClass(className.front) ) {
471
- module.hide();
472
- }
473
- }
474
- else {
475
- module.debug('Escape key pressed, but closable is set to false');
476
- }
477
- event.preventDefault();
478
- }
479
- },
480
- resize: function() {
481
- if( $dimmable.dimmer('is active') && ( module.is.animating() || module.is.active() ) ) {
482
- requestAnimationFrame(module.refresh);
483
- }
484
- }
485
- },
343
+ attachEvents: function (selector, event) {
344
+ var
345
+ $toggle = $(selector)
346
+ ;
347
+ event = isFunction(module[event])
348
+ ? module[event]
349
+ : module.toggle;
350
+ if ($toggle.length > 0) {
351
+ module.debug('Attaching modal events to element', selector, event);
352
+ $toggle
353
+ .off(eventNamespace)
354
+ .on('click' + eventNamespace, event)
355
+ ;
356
+ } else {
357
+ module.error(error.notFound, selector);
358
+ }
359
+ },
486
360
 
487
- toggle: function() {
488
- if( module.is.active() || module.is.animating() ) {
489
- module.hide();
490
- }
491
- else {
492
- module.show();
493
- }
494
- },
361
+ bind: {
362
+ events: function () {
363
+ module.verbose('Attaching events');
364
+ $module
365
+ .on('click' + eventNamespace, selector.close, module.event.close)
366
+ .on('click' + eventNamespace, selector.approve, module.event.approve)
367
+ .on('click' + eventNamespace, selector.deny, module.event.deny)
368
+ ;
369
+ $closeIcon
370
+ .on('keyup' + elementEventNamespace, module.event.closeKeyUp)
371
+ ;
372
+ $window
373
+ .on('resize' + elementEventNamespace, module.event.resize)
374
+ .on('focus' + elementEventNamespace, module.event.focus)
375
+ ;
376
+ },
377
+ scrollLock: function () {
378
+ // touch events default to passive, due to changes in chrome to optimize mobile perf
379
+ $dimmable[0].addEventListener('touchmove', module.event.preventScroll, { passive: false });
380
+ },
381
+ },
495
382
 
496
- show: function(callback) {
497
- callback = $.isFunction(callback)
498
- ? callback
499
- : function(){}
500
- ;
501
- module.refreshModals();
502
- module.set.dimmerSettings();
503
- module.set.dimmerStyles();
383
+ unbind: {
384
+ scrollLock: function () {
385
+ $dimmable[0].removeEventListener('touchmove', module.event.preventScroll, { passive: false });
386
+ },
387
+ },
504
388
 
505
- module.showModal(callback);
506
- },
389
+ get: {
390
+ id: function () {
391
+ return id;
392
+ },
393
+ element: function () {
394
+ return $module;
395
+ },
396
+ settings: function () {
397
+ return settings;
398
+ },
399
+ },
507
400
 
508
- hide: function(callback) {
509
- callback = $.isFunction(callback)
510
- ? callback
511
- : function(){}
512
- ;
513
- module.refreshModals();
514
- return module.hideModal(callback);
515
- },
401
+ event: {
402
+ approve: function () {
403
+ if (ignoreRepeatedEvents || settings.onApprove.call(element, $(this)) === false) {
404
+ module.verbose('Approve callback returned false cancelling hide');
405
+
406
+ return;
407
+ }
408
+ ignoreRepeatedEvents = true;
409
+ module.hide(function () {
410
+ ignoreRepeatedEvents = false;
411
+ });
412
+ },
413
+ preventScroll: function (event) {
414
+ if (event.target.className.indexOf('dimmer') !== -1) {
415
+ event.preventDefault();
416
+ }
417
+ },
418
+ deny: function () {
419
+ if (ignoreRepeatedEvents || settings.onDeny.call(element, $(this)) === false) {
420
+ module.verbose('Deny callback returned false cancelling hide');
421
+
422
+ return;
423
+ }
424
+ ignoreRepeatedEvents = true;
425
+ module.hide(function () {
426
+ ignoreRepeatedEvents = false;
427
+ });
428
+ },
429
+ close: function () {
430
+ module.hide();
431
+ },
432
+ closeKeyUp: function (event) {
433
+ var
434
+ keyCode = event.which
435
+ ;
436
+ if ((keyCode === settings.keys.enter || keyCode === settings.keys.space) && $module.hasClass(className.front)) {
437
+ module.hide();
438
+ }
439
+ },
440
+ inputKeyDown: {
441
+ first: function (event) {
442
+ var
443
+ keyCode = event.which
444
+ ;
445
+ if (keyCode === settings.keys.tab && event.shiftKey) {
446
+ $inputs.last().trigger('focus');
447
+ event.preventDefault();
448
+ }
449
+ },
450
+ last: function (event) {
451
+ var
452
+ keyCode = event.which
453
+ ;
454
+ if (keyCode === settings.keys.tab && !event.shiftKey) {
455
+ $inputs.first().trigger('focus');
456
+ event.preventDefault();
457
+ }
458
+ },
459
+ },
460
+ mousedown: function (event) {
461
+ var
462
+ $target = $(event.target),
463
+ isRtl = module.is.rtl()
464
+ ;
465
+ initialMouseDownInModal = $target.closest(selector.modal).length > 0;
466
+ if (initialMouseDownInModal) {
467
+ module.verbose('Mouse down event registered inside the modal');
468
+ }
469
+ initialMouseDownInScrollbar = module.is.scrolling() && ((!isRtl && $window.outerWidth() - settings.scrollbarWidth <= event.clientX) || (isRtl && settings.scrollbarWidth >= event.clientX));
470
+ if (initialMouseDownInScrollbar) {
471
+ module.verbose('Mouse down event registered inside the scrollbar');
472
+ }
473
+ },
474
+ mouseup: function (event) {
475
+ if (!settings.closable) {
476
+ module.verbose('Dimmer clicked but closable setting is disabled');
477
+
478
+ return;
479
+ }
480
+ if (initialMouseDownInModal) {
481
+ module.debug('Dimmer clicked but mouse down was initially registered inside the modal');
482
+
483
+ return;
484
+ }
485
+ if (initialMouseDownInScrollbar) {
486
+ module.debug('Dimmer clicked but mouse down was initially registered inside the scrollbar');
487
+
488
+ return;
489
+ }
490
+ var
491
+ $target = $(event.target),
492
+ isInModal = $target.closest(selector.modal).length > 0,
493
+ isInDOM = $.contains(document.documentElement, event.target)
494
+ ;
495
+ if (!isInModal && isInDOM && module.is.active() && $module.hasClass(className.front)) {
496
+ module.debug('Dimmer clicked, hiding all modals');
497
+ if (settings.allowMultiple) {
498
+ if (!module.hideAll()) {
499
+ return;
500
+ }
501
+ } else if (!module.hide()) {
502
+ return;
503
+ }
504
+ module.remove.clickaway();
505
+ }
506
+ },
507
+ debounce: function (method, delay) {
508
+ clearTimeout(module.timer);
509
+ module.timer = setTimeout(method, delay);
510
+ },
511
+ keyboard: function (event) {
512
+ var
513
+ keyCode = event.which
514
+ ;
515
+ if (keyCode === settings.keys.escape) {
516
+ if (settings.closable) {
517
+ module.debug('Escape key pressed hiding modal');
518
+ if ($module.hasClass(className.front)) {
519
+ module.hide();
520
+ }
521
+ } else {
522
+ module.debug('Escape key pressed, but closable is set to false');
523
+ }
524
+ event.preventDefault();
525
+ }
526
+ },
527
+ resize: function () {
528
+ if ($dimmable.dimmer('is active') && (module.is.animating() || module.is.active())) {
529
+ requestAnimationFrame(module.refresh);
530
+ }
531
+ },
532
+ focus: function () {
533
+ if ($dimmable.dimmer('is active') && module.is.active() && settings.autofocus) {
534
+ requestAnimationFrame(module.set.autofocus);
535
+ }
536
+ },
537
+ },
516
538
 
517
- showModal: function(callback) {
518
- callback = $.isFunction(callback)
519
- ? callback
520
- : function(){}
521
- ;
522
- if( module.is.animating() || !module.is.active() ) {
523
- if(settings.onShow.call(element) === false) {
524
- module.verbose('Show callback returned false cancelling show');
525
- return;
526
- }
527
- hadScrollbar = module.has.scrollbar();
528
- module.showDimmer();
529
- module.cacheSizes();
530
- if(hadScrollbar) {
531
- module.set.bodyMargin();
532
- }
533
- if(module.can.useFlex()) {
534
- module.remove.legacy();
535
- }
536
- else {
537
- module.set.legacy();
538
- module.set.modalOffset();
539
- module.debug('Using non-flex legacy modal positioning.');
540
- }
541
- module.set.screenHeight();
542
- module.set.type();
543
- module.set.clickaway();
539
+ toggle: function () {
540
+ if (module.is.active() || module.is.animating()) {
541
+ module.hide();
542
+ } else {
543
+ module.show();
544
+ }
545
+ },
544
546
 
545
- if( !settings.allowMultiple && module.others.active() ) {
546
- module.hideOthers(module.showModal);
547
- }
548
- else {
549
- ignoreRepeatedEvents = false;
550
- if( settings.allowMultiple ) {
551
- if ( module.others.active() ) {
552
- $otherModals.filter('.' + className.active).find(selector.dimmer).addClass('active');
553
- }
547
+ show: function (callback) {
548
+ callback = isFunction(callback)
549
+ ? callback
550
+ : function () {};
551
+ module.refreshModals();
552
+ module.set.dimmerSettings();
553
+ module.set.dimmerStyles();
554
554
 
555
- if ( settings.detachable ) {
556
- $module.detach().appendTo($dimmer);
557
- }
558
- }
559
- if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
560
- module.debug('Showing modal with css animations');
561
- $module
562
- .transition({
563
- debug : settings.debug,
564
- verbose : settings.verbose,
565
- silent : settings.silent,
566
- animation : (settings.transition.showMethod || settings.transition) + ' in',
567
- queue : settings.queue,
568
- duration : settings.transition.showDuration || settings.duration,
569
- useFailSafe : true,
570
- onComplete : function() {
571
- settings.onVisible.apply(element);
572
- if(settings.keyboardShortcuts) {
573
- module.add.keyboardShortcuts();
574
- }
575
- module.save.focus();
576
- module.set.active();
577
- module.refreshInputs()
578
- if(settings.autofocus) {
579
- module.set.autofocus();
580
- }
581
- callback();
555
+ module.showModal(callback);
556
+ },
557
+
558
+ hide: function (callback) {
559
+ callback = isFunction(callback)
560
+ ? callback
561
+ : function () {};
562
+ module.refreshModals();
563
+
564
+ return module.hideModal(callback);
565
+ },
566
+
567
+ showModal: function (callback) {
568
+ callback = isFunction(callback)
569
+ ? callback
570
+ : function () {};
571
+ if (module.is.animating() || !module.is.active()) {
572
+ if (settings.onShow.call(element) === false) {
573
+ module.verbose('Show callback returned false cancelling show');
574
+
575
+ return;
576
+ }
577
+ hadScrollbar = module.has.scrollbar();
578
+ module.showDimmer();
579
+ module.cacheSizes();
580
+ if (hadScrollbar) {
581
+ module.set.bodyMargin();
582
+ }
583
+ if (module.can.useFlex()) {
584
+ module.remove.legacy();
585
+ } else {
586
+ module.set.legacy();
587
+ module.set.modalOffset();
588
+ module.debug('Using non-flex legacy modal positioning.');
589
+ }
590
+ module.set.screenHeight();
591
+ module.set.type();
592
+ module.set.clickaway();
593
+
594
+ if (!settings.allowMultiple && module.others.active()) {
595
+ module.hideOthers(module.showModal);
596
+ } else {
597
+ ignoreRepeatedEvents = false;
598
+ if (settings.allowMultiple) {
599
+ if (module.others.active()) {
600
+ $otherModals.filter('.' + className.active).find(selector.dimmer).addClass('active');
601
+ }
602
+
603
+ if (settings.detachable) {
604
+ $module.detach().appendTo($dimmer);
605
+ }
606
+ }
607
+ if (settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
608
+ module.debug('Showing modal with css animations');
609
+ $module
610
+ .transition({
611
+ debug: settings.debug,
612
+ verbose: settings.verbose,
613
+ silent: settings.silent,
614
+ animation: (settings.transition.showMethod || settings.transition) + ' in',
615
+ queue: settings.queue,
616
+ duration: settings.transition.showDuration || settings.duration,
617
+ useFailSafe: true,
618
+ onComplete: function () {
619
+ settings.onVisible.apply(element);
620
+ if (settings.keyboardShortcuts) {
621
+ module.add.keyboardShortcuts();
622
+ }
623
+ module.save.focus();
624
+ module.set.active();
625
+ module.refreshInputs();
626
+ callback();
627
+ },
628
+ })
629
+ ;
630
+ } else {
631
+ module.error(error.noTransition);
632
+ }
633
+ }
634
+ } else {
635
+ module.debug('Modal is already visible');
636
+ }
637
+ },
638
+
639
+ hideModal: function (callback, keepDimmed, hideOthersToo) {
640
+ var
641
+ $previousModal = $otherModals.filter('.' + className.active).last()
642
+ ;
643
+ callback = isFunction(callback)
644
+ ? callback
645
+ : function () {};
646
+ if (settings.onHide.call(element, $(this)) === false) {
647
+ module.verbose('Hide callback returned false cancelling hide');
648
+ ignoreRepeatedEvents = false;
649
+
650
+ return false;
582
651
  }
583
- })
584
- ;
585
- }
586
- else {
587
- module.error(error.noTransition);
588
- }
589
- }
590
- }
591
- else {
592
- module.debug('Modal is already visible');
593
- }
594
- },
595
652
 
596
- hideModal: function(callback, keepDimmed, hideOthersToo) {
597
- var
598
- $previousModal = $otherModals.filter('.' + className.active).last()
599
- ;
600
- callback = $.isFunction(callback)
601
- ? callback
602
- : function(){}
603
- ;
604
- if(settings.onHide.call(element, $(this)) === false) {
605
- module.verbose('Hide callback returned false cancelling hide');
606
- ignoreRepeatedEvents = false;
607
- return false;
608
- }
609
-
610
- if( module.is.animating() || module.is.active() ) {
611
- module.debug('Hiding modal');
612
- if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
613
- module.remove.active();
614
- $module
615
- .transition({
616
- debug : settings.debug,
617
- verbose : settings.verbose,
618
- silent : settings.silent,
619
- animation : (settings.transition.hideMethod || settings.transition) + ' out',
620
- queue : settings.queue,
621
- duration : settings.transition.hideDuration || settings.duration,
622
- useFailSafe : true,
623
- onStart : function() {
624
- if(!module.others.active() && !module.others.animating() && !keepDimmed) {
625
- module.hideDimmer();
653
+ if (module.is.animating() || module.is.active()) {
654
+ module.debug('Hiding modal');
655
+ if (settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
656
+ module.remove.active();
657
+ $module
658
+ .transition({
659
+ debug: settings.debug,
660
+ verbose: settings.verbose,
661
+ silent: settings.silent,
662
+ animation: (settings.transition.hideMethod || settings.transition) + ' out',
663
+ queue: settings.queue,
664
+ duration: settings.transition.hideDuration || settings.duration,
665
+ useFailSafe: true,
666
+ onStart: function () {
667
+ if (!module.others.active() && !module.others.animating() && !keepDimmed) {
668
+ module.hideDimmer();
669
+ }
670
+ if (settings.keyboardShortcuts && !module.others.active()) {
671
+ module.remove.keyboardShortcuts();
672
+ }
673
+ },
674
+ onComplete: function () {
675
+ module.unbind.scrollLock();
676
+ if (settings.allowMultiple) {
677
+ $previousModal.addClass(className.front);
678
+ $module.removeClass(className.front);
679
+
680
+ if (hideOthersToo) {
681
+ $allModals.find(selector.dimmer).removeClass('active');
682
+ } else {
683
+ $previousModal.find(selector.dimmer).removeClass('active');
684
+ }
685
+ }
686
+ if (isFunction(settings.onHidden)) {
687
+ settings.onHidden.call(element);
688
+ }
689
+ module.remove.dimmerStyles();
690
+ module.restore.focus();
691
+ callback();
692
+ },
693
+ })
694
+ ;
695
+ } else {
696
+ module.error(error.noTransition);
697
+ }
626
698
  }
627
- if( settings.keyboardShortcuts && !module.others.active() ) {
628
- module.remove.keyboardShortcuts();
699
+ },
700
+
701
+ showDimmer: function () {
702
+ if ($dimmable.dimmer('is animating') || !$dimmable.dimmer('is active')) {
703
+ if (hadScrollbar) {
704
+ if (!isBody) {
705
+ $dimmer.css('top', $dimmable.scrollTop());
706
+ }
707
+ module.save.bodyMargin();
708
+ }
709
+ module.debug('Showing dimmer');
710
+ $dimmable.dimmer('show');
711
+ } else {
712
+ module.debug('Dimmer already visible');
629
713
  }
630
- },
631
- onComplete : function() {
632
- module.unbind.scrollLock();
633
- if ( settings.allowMultiple ) {
634
- $previousModal.addClass(className.front);
635
- $module.removeClass(className.front);
636
-
637
- if ( hideOthersToo ) {
638
- $allModals.find(selector.dimmer).removeClass('active');
639
- }
640
- else {
641
- $previousModal.find(selector.dimmer).removeClass('active');
642
- }
714
+ },
715
+
716
+ hideDimmer: function () {
717
+ if ($dimmable.dimmer('is animating') || $dimmable.dimmer('is active')) {
718
+ module.unbind.scrollLock();
719
+ $dimmable.dimmer('hide', function () {
720
+ if (hadScrollbar) {
721
+ module.restore.bodyMargin();
722
+ }
723
+ module.remove.clickaway();
724
+ module.remove.screenHeight();
725
+ });
726
+ } else {
727
+ module.debug('Dimmer is not visible cannot hide');
643
728
  }
644
- if($.isFunction(settings.onHidden)) {
645
- settings.onHidden.call(element);
729
+ },
730
+
731
+ hideAll: function (callback) {
732
+ var
733
+ $visibleModals = $allModals.filter('.' + className.active + ', .' + className.animating)
734
+ ;
735
+ callback = isFunction(callback)
736
+ ? callback
737
+ : function () {};
738
+ if ($visibleModals.length > 0) {
739
+ module.debug('Hiding all visible modals');
740
+ var hideOk = true;
741
+ // check in reverse order trying to hide most top displayed modal first
742
+ $($visibleModals.get().reverse()).each(function (index, element) {
743
+ if (hideOk) {
744
+ hideOk = $(element).modal('hide modal', callback, false, true);
745
+ }
746
+ });
747
+ if (hideOk) {
748
+ module.hideDimmer();
749
+ }
750
+
751
+ return hideOk;
646
752
  }
647
- module.remove.dimmerStyles();
648
- module.restore.focus();
649
- callback();
650
- }
651
- })
652
- ;
653
- }
654
- else {
655
- module.error(error.noTransition);
656
- }
657
- }
658
- },
753
+ },
659
754
 
660
- showDimmer: function() {
661
- if($dimmable.dimmer('is animating') || !$dimmable.dimmer('is active') ) {
662
- if(hadScrollbar) {
663
- if(!isBody) {
664
- $dimmer.css('top', $dimmable.scrollTop());
665
- }
666
- module.save.bodyMargin();
667
- }
668
- module.debug('Showing dimmer');
669
- $dimmable.dimmer('show');
670
- }
671
- else {
672
- module.debug('Dimmer already visible');
673
- }
674
- },
755
+ hideOthers: function (callback) {
756
+ var
757
+ $visibleModals = $otherModals.filter('.' + className.active + ', .' + className.animating)
758
+ ;
759
+ callback = isFunction(callback)
760
+ ? callback
761
+ : function () {};
762
+ if ($visibleModals.length > 0) {
763
+ module.debug('Hiding other modals', $otherModals);
764
+ $visibleModals
765
+ .modal('hide modal', callback, true)
766
+ ;
767
+ }
768
+ },
675
769
 
676
- hideDimmer: function() {
677
- if( $dimmable.dimmer('is animating') || ($dimmable.dimmer('is active')) ) {
678
- module.unbind.scrollLock();
679
- $dimmable.dimmer('hide', function() {
680
- if(hadScrollbar) {
681
- module.restore.bodyMargin();
682
- }
683
- module.remove.clickaway();
684
- module.remove.screenHeight();
685
- });
686
- }
687
- else {
688
- module.debug('Dimmer is not visible cannot hide');
689
- }
690
- },
770
+ others: {
771
+ active: function () {
772
+ return $otherModals.filter('.' + className.active).length > 0;
773
+ },
774
+ animating: function () {
775
+ return $otherModals.filter('.' + className.animating).length > 0;
776
+ },
777
+ },
691
778
 
692
- hideAll: function(callback) {
693
- var
694
- $visibleModals = $allModals.filter('.' + className.active + ', .' + className.animating)
695
- ;
696
- callback = $.isFunction(callback)
697
- ? callback
698
- : function(){}
699
- ;
700
- if( $visibleModals.length > 0 ) {
701
- module.debug('Hiding all visible modals');
702
- var hideOk = true;
703
- //check in reverse order trying to hide most top displayed modal first
704
- $($visibleModals.get().reverse()).each(function(index,element){
705
- if(hideOk){
706
- hideOk = $(element).modal('hide modal', callback, false, true);
779
+ add: {
780
+ keyboardShortcuts: function () {
781
+ module.verbose('Adding keyboard shortcuts');
782
+ $document
783
+ .on('keydown' + eventNamespace, module.event.keyboard)
784
+ ;
785
+ },
786
+ },
787
+
788
+ save: {
789
+ focus: function () {
790
+ var
791
+ $activeElement = $(document.activeElement),
792
+ inCurrentModal = $activeElement.closest($module).length > 0
793
+ ;
794
+ if (!inCurrentModal) {
795
+ $focusedElement = $(document.activeElement).trigger('blur');
796
+ }
797
+ },
798
+ bodyMargin: function () {
799
+ initialBodyMargin = $context.css((isBody ? 'margin-' : 'padding-') + (module.can.leftBodyScrollbar() ? 'left' : 'right'));
800
+ var
801
+ bodyMarginRightPixel = parseInt(initialBodyMargin.replace(/[^\d.]/g, ''), 10),
802
+ bodyScrollbarWidth = isBody ? window.innerWidth - document.documentElement.clientWidth : $context[0].offsetWidth - $context[0].clientWidth
803
+ ;
804
+ tempBodyMargin = bodyMarginRightPixel + bodyScrollbarWidth;
805
+ },
806
+ },
807
+
808
+ restore: {
809
+ focus: function () {
810
+ if ($focusedElement && $focusedElement.length > 0 && settings.restoreFocus) {
811
+ $focusedElement.trigger('focus');
812
+ }
813
+ },
814
+ bodyMargin: function () {
815
+ var position = module.can.leftBodyScrollbar() ? 'left' : 'right';
816
+ $context.css((isBody ? 'margin-' : 'padding-') + position, initialBodyMargin);
817
+ $context.find(selector.bodyFixed.replace('right', position)).each(function () {
818
+ var
819
+ el = $(this),
820
+ attribute = el.css('position') === 'fixed' ? 'padding-' + position : position
821
+ ;
822
+ el.css(attribute, '');
823
+ });
824
+ },
825
+ },
826
+
827
+ remove: {
828
+ active: function () {
829
+ $module.removeClass(className.active);
830
+ },
831
+ legacy: function () {
832
+ $module.removeClass(className.legacy);
833
+ },
834
+ clickaway: function () {
835
+ if (!settings.detachable) {
836
+ $module
837
+ .off('mousedown' + elementEventNamespace)
838
+ ;
839
+ }
840
+ $dimmer
841
+ .off('mousedown' + elementEventNamespace)
842
+ ;
843
+ $dimmer
844
+ .off('mouseup' + elementEventNamespace)
845
+ ;
846
+ },
847
+ dimmerStyles: function () {
848
+ $dimmer.removeClass(className.inverted);
849
+ $dimmable.removeClass(className.blurring);
850
+ },
851
+ bodyStyle: function () {
852
+ if ($context.attr('style') === '') {
853
+ module.verbose('Removing style attribute');
854
+ $context.removeAttr('style');
855
+ }
856
+ },
857
+ screenHeight: function () {
858
+ module.debug('Removing page height');
859
+ $context
860
+ .css('height', '')
861
+ ;
862
+ module.remove.bodyStyle();
863
+ },
864
+ keyboardShortcuts: function () {
865
+ module.verbose('Removing keyboard shortcuts');
866
+ $document
867
+ .off('keydown' + eventNamespace)
868
+ ;
869
+ },
870
+ scrolling: function () {
871
+ if (!keepScrollingClass) {
872
+ $dimmable.removeClass(className.scrolling);
873
+ }
874
+ $module.removeClass(className.scrolling);
875
+ },
876
+ },
877
+
878
+ cacheSizes: function () {
879
+ $module.addClass(className.loading);
880
+ var
881
+ scrollHeight = $module.prop('scrollHeight'),
882
+ modalWidth = $module.outerWidth(),
883
+ modalHeight = $module.outerHeight()
884
+ ;
885
+ if (module.cache.pageHeight === undefined || modalHeight !== 0) {
886
+ $.extend(module.cache, {
887
+ pageHeight: $document.outerHeight(),
888
+ width: modalWidth,
889
+ height: modalHeight + settings.offset,
890
+ scrollHeight: scrollHeight + settings.offset,
891
+ contextHeight: isBody
892
+ ? $window.height()
893
+ : $dimmable.height(),
894
+ });
895
+ module.cache.topOffset = -(module.cache.height / 2);
896
+ }
897
+ $module.removeClass(className.loading);
898
+ module.debug('Caching modal and container sizes', module.cache);
899
+ },
900
+ helpers: {
901
+ deQuote: function (string) {
902
+ return String(string).replace(/"/g, '');
903
+ },
904
+ escape: function (string, preserveHTML) {
905
+ if (preserveHTML) {
906
+ return string;
907
+ }
908
+ var
909
+ badChars = /["'<>`]/g,
910
+ shouldEscape = /["&'<>`]/,
911
+ escape = {
912
+ '<': '&lt;',
913
+ '>': '&gt;',
914
+ '"': '&quot;',
915
+ "'": '&#x27;',
916
+ '`': '&#x60;',
917
+ },
918
+ escapedChar = function (chr) {
919
+ return escape[chr];
920
+ }
921
+ ;
922
+ if (shouldEscape.test(string)) {
923
+ string = string.replace(/&(?![\d#a-z]{1,12};)/gi, '&amp;');
924
+
925
+ return string.replace(badChars, escapedChar);
926
+ }
927
+
928
+ return string;
929
+ },
930
+ },
931
+ can: {
932
+ leftBodyScrollbar: function () {
933
+ if (module.cache.leftBodyScrollbar === undefined) {
934
+ module.cache.leftBodyScrollbar = module.is.rtl() && ((module.is.iframe && !module.is.firefox()) || module.is.safari() || module.is.edge() || module.is.ie());
935
+ }
936
+
937
+ return module.cache.leftBodyScrollbar;
938
+ },
939
+ useFlex: function () {
940
+ if (settings.useFlex === 'auto') {
941
+ return settings.detachable && !module.is.ie();
942
+ }
943
+ if (settings.useFlex && module.is.ie()) {
944
+ module.debug('useFlex true is not supported in IE');
945
+ } else if (settings.useFlex && !settings.detachable) {
946
+ module.debug('useFlex true in combination with detachable false is not supported');
947
+ }
948
+
949
+ return settings.useFlex;
950
+ },
951
+ fit: function () {
952
+ var
953
+ contextHeight = module.cache.contextHeight,
954
+ verticalCenter = module.cache.contextHeight / 2,
955
+ topOffset = module.cache.topOffset,
956
+ scrollHeight = module.cache.scrollHeight,
957
+ height = module.cache.height,
958
+ paddingHeight = settings.padding,
959
+ startPosition = verticalCenter + topOffset
960
+ ;
961
+
962
+ return scrollHeight > height
963
+ ? startPosition + scrollHeight + paddingHeight < contextHeight
964
+ : height + (paddingHeight * 2) < contextHeight;
965
+ },
966
+ },
967
+ has: {
968
+ configActions: function () {
969
+ return Array.isArray(settings.actions) && settings.actions.length > 0;
970
+ },
971
+ scrollbar: function () {
972
+ return isBody || $context.css('overflow-y') !== 'hidden';
973
+ },
974
+ },
975
+ is: {
976
+ active: function () {
977
+ return $module.hasClass(className.active);
978
+ },
979
+ ie: function () {
980
+ if (module.cache.isIE === undefined) {
981
+ var
982
+ isIE11 = !window.ActiveXObject && 'ActiveXObject' in window,
983
+ isIE = 'ActiveXObject' in window
984
+ ;
985
+ module.cache.isIE = isIE11 || isIE;
986
+ }
987
+
988
+ return module.cache.isIE;
989
+ },
990
+ animating: function () {
991
+ return $module.transition('is supported')
992
+ ? $module.transition('is animating')
993
+ : $module.is(':visible');
994
+ },
995
+ scrolling: function () {
996
+ return $dimmable.hasClass(className.scrolling);
997
+ },
998
+ modernBrowser: function () {
999
+ // appName for IE11 reports 'Netscape' can no longer use
1000
+ return !(window.ActiveXObject || 'ActiveXObject' in window);
1001
+ },
1002
+ rtl: function () {
1003
+ if (module.cache.isRTL === undefined) {
1004
+ module.cache.isRTL = $module.attr('dir') === 'rtl' || $module.css('direction') === 'rtl' || $body.attr('dir') === 'rtl' || $body.css('direction') === 'rtl' || $context.attr('dir') === 'rtl' || $context.css('direction') === 'rtl';
1005
+ }
1006
+
1007
+ return module.cache.isRTL;
1008
+ },
1009
+ safari: function () {
1010
+ if (module.cache.isSafari === undefined) {
1011
+ module.cache.isSafari = /constructor/i.test(window.HTMLElement) || !!window.ApplePaySession;
1012
+ }
1013
+
1014
+ return module.cache.isSafari;
1015
+ },
1016
+ edge: function () {
1017
+ if (module.cache.isEdge === undefined) {
1018
+ module.cache.isEdge = !!window.setImmediate && !module.is.ie();
1019
+ }
1020
+
1021
+ return module.cache.isEdge;
1022
+ },
1023
+ firefox: function () {
1024
+ if (module.cache.isFirefox === undefined) {
1025
+ module.cache.isFirefox = !!window.InstallTrigger;
1026
+ }
1027
+
1028
+ return module.cache.isFirefox;
1029
+ },
1030
+ iframe: function () {
1031
+ return !(self === top);
1032
+ },
1033
+ },
1034
+
1035
+ set: {
1036
+ autofocus: function () {
1037
+ var
1038
+ $autofocus = $inputs.filter('[autofocus]'),
1039
+ $rawInputs = $inputs.filter(':input'),
1040
+ $input = $autofocus.length > 0
1041
+ ? $autofocus.first()
1042
+ : ($rawInputs.length > 0
1043
+ ? $rawInputs
1044
+ : $inputs.filter(':not(i.close)')
1045
+ ).first()
1046
+ ;
1047
+ // check if only the close icon is remaining
1048
+ if ($input.length === 0 && $inputs.length > 0) {
1049
+ $input = $inputs.first();
1050
+ }
1051
+ if ($input.length > 0) {
1052
+ $input.trigger('focus');
1053
+ }
1054
+ },
1055
+ bodyMargin: function () {
1056
+ var position = module.can.leftBodyScrollbar() ? 'left' : 'right';
1057
+ if (settings.detachable || module.can.fit()) {
1058
+ $context.css((isBody ? 'margin-' : 'padding-') + position, tempBodyMargin + 'px');
1059
+ }
1060
+ $context.find(selector.bodyFixed.replace('right', position)).each(function () {
1061
+ var
1062
+ el = $(this),
1063
+ attribute = el.css('position') === 'fixed' ? 'padding-' + position : position
1064
+ ;
1065
+ el.css(attribute, 'calc(' + el.css(attribute) + ' + ' + tempBodyMargin + 'px)');
1066
+ });
1067
+ },
1068
+ clickaway: function () {
1069
+ if (!settings.detachable) {
1070
+ $module
1071
+ .on('mousedown' + elementEventNamespace, module.event.mousedown)
1072
+ ;
1073
+ }
1074
+ $dimmer
1075
+ .on('mousedown' + elementEventNamespace, module.event.mousedown)
1076
+ ;
1077
+ $dimmer
1078
+ .on('mouseup' + elementEventNamespace, module.event.mouseup)
1079
+ ;
1080
+ },
1081
+ dimmerSettings: function () {
1082
+ if ($.fn.dimmer === undefined) {
1083
+ module.error(error.dimmer);
1084
+
1085
+ return;
1086
+ }
1087
+ var
1088
+ defaultSettings = {
1089
+ debug: settings.debug,
1090
+ dimmerName: 'modals',
1091
+ closable: 'auto',
1092
+ useFlex: module.can.useFlex(),
1093
+ duration: {
1094
+ show: settings.transition.showDuration || settings.duration,
1095
+ hide: settings.transition.hideDuration || settings.duration,
1096
+ },
1097
+ },
1098
+ dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
1099
+ ;
1100
+ if (settings.inverted) {
1101
+ dimmerSettings.variation = dimmerSettings.variation !== undefined
1102
+ ? dimmerSettings.variation + ' inverted'
1103
+ : 'inverted';
1104
+ }
1105
+ $context.dimmer('setting', dimmerSettings);
1106
+ },
1107
+ dimmerStyles: function () {
1108
+ if (settings.inverted) {
1109
+ $dimmer.addClass(className.inverted);
1110
+ } else {
1111
+ $dimmer.removeClass(className.inverted);
1112
+ }
1113
+ if (settings.blurring) {
1114
+ $dimmable.addClass(className.blurring);
1115
+ } else {
1116
+ $dimmable.removeClass(className.blurring);
1117
+ }
1118
+ },
1119
+ modalOffset: function () {
1120
+ if (!settings.detachable) {
1121
+ var canFit = module.can.fit();
1122
+ $module
1123
+ .css({
1124
+ top: !$module.hasClass('aligned') && canFit
1125
+ ? $document.scrollTop() + (module.cache.contextHeight - module.cache.height) / 2
1126
+ : (!canFit || $module.hasClass('top')
1127
+ ? $document.scrollTop() + settings.padding
1128
+ : $document.scrollTop() + (module.cache.contextHeight - module.cache.height - settings.padding)),
1129
+ marginLeft: -(module.cache.width / 2),
1130
+ })
1131
+ ;
1132
+ } else {
1133
+ $module
1134
+ .css({
1135
+ marginTop: !$module.hasClass('aligned') && module.can.fit()
1136
+ ? -(module.cache.height / 2)
1137
+ : settings.padding / 2,
1138
+ marginLeft: -(module.cache.width / 2),
1139
+ })
1140
+ ;
1141
+ }
1142
+ module.verbose('Setting modal offset for legacy mode');
1143
+ },
1144
+ screenHeight: function () {
1145
+ if (module.can.fit()) {
1146
+ $context.css('height', '');
1147
+ } else if (!$module.hasClass('bottom')) {
1148
+ module.debug('Modal is taller than page content, resizing page height');
1149
+ $context
1150
+ .css('height', module.cache.height + (settings.padding * 2) + 'px')
1151
+ ;
1152
+ }
1153
+ },
1154
+ active: function () {
1155
+ $module.addClass(className.active + ' ' + className.front);
1156
+ $otherModals.filter('.' + className.active).removeClass(className.front);
1157
+ },
1158
+ scrolling: function () {
1159
+ $dimmable.addClass(className.scrolling);
1160
+ $module.addClass(className.scrolling);
1161
+ module.unbind.scrollLock();
1162
+ },
1163
+ legacy: function () {
1164
+ $module.addClass(className.legacy);
1165
+ },
1166
+ type: function () {
1167
+ if (module.can.fit()) {
1168
+ module.verbose('Modal fits on screen');
1169
+ if (!module.others.active() && !module.others.animating()) {
1170
+ module.remove.scrolling();
1171
+ module.bind.scrollLock();
1172
+ }
1173
+ } else if (!$module.hasClass('bottom')) {
1174
+ module.verbose('Modal cannot fit on screen setting to scrolling');
1175
+ module.set.scrolling();
1176
+ } else {
1177
+ module.verbose('Bottom aligned modal not fitting on screen is unsupported for scrolling');
1178
+ }
1179
+ },
1180
+ undetached: function () {
1181
+ $dimmable.addClass(className.undetached);
1182
+ },
1183
+ },
1184
+
1185
+ setting: function (name, value) {
1186
+ module.debug('Changing setting', name, value);
1187
+ if ($.isPlainObject(name)) {
1188
+ $.extend(true, settings, name);
1189
+ } else if (value !== undefined) {
1190
+ if ($.isPlainObject(settings[name])) {
1191
+ $.extend(true, settings[name], value);
1192
+ } else {
1193
+ settings[name] = value;
1194
+ }
1195
+ } else {
1196
+ return settings[name];
1197
+ }
1198
+ },
1199
+ internal: function (name, value) {
1200
+ if ($.isPlainObject(name)) {
1201
+ $.extend(true, module, name);
1202
+ } else if (value !== undefined) {
1203
+ module[name] = value;
1204
+ } else {
1205
+ return module[name];
1206
+ }
1207
+ },
1208
+ debug: function () {
1209
+ if (!settings.silent && settings.debug) {
1210
+ if (settings.performance) {
1211
+ module.performance.log(arguments);
1212
+ } else {
1213
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
1214
+ module.debug.apply(console, arguments);
1215
+ }
1216
+ }
1217
+ },
1218
+ verbose: function () {
1219
+ if (!settings.silent && settings.verbose && settings.debug) {
1220
+ if (settings.performance) {
1221
+ module.performance.log(arguments);
1222
+ } else {
1223
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
1224
+ module.verbose.apply(console, arguments);
1225
+ }
1226
+ }
1227
+ },
1228
+ error: function () {
1229
+ if (!settings.silent) {
1230
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
1231
+ module.error.apply(console, arguments);
1232
+ }
1233
+ },
1234
+ performance: {
1235
+ log: function (message) {
1236
+ var
1237
+ currentTime,
1238
+ executionTime,
1239
+ previousTime
1240
+ ;
1241
+ if (settings.performance) {
1242
+ currentTime = Date.now();
1243
+ previousTime = time || currentTime;
1244
+ executionTime = currentTime - previousTime;
1245
+ time = currentTime;
1246
+ performance.push({
1247
+ Name: message[0],
1248
+ Arguments: [].slice.call(message, 1) || '',
1249
+ Element: element,
1250
+ 'Execution Time': executionTime,
1251
+ });
1252
+ }
1253
+ clearTimeout(module.performance.timer);
1254
+ module.performance.timer = setTimeout(module.performance.display, 500);
1255
+ },
1256
+ display: function () {
1257
+ var
1258
+ title = settings.name + ':',
1259
+ totalTime = 0
1260
+ ;
1261
+ time = false;
1262
+ clearTimeout(module.performance.timer);
1263
+ $.each(performance, function (index, data) {
1264
+ totalTime += data['Execution Time'];
1265
+ });
1266
+ title += ' ' + totalTime + 'ms';
1267
+ if (moduleSelector) {
1268
+ title += ' \'' + moduleSelector + '\'';
1269
+ }
1270
+ if (performance.length > 0) {
1271
+ console.groupCollapsed(title);
1272
+ if (console.table) {
1273
+ console.table(performance);
1274
+ } else {
1275
+ $.each(performance, function (index, data) {
1276
+ console.log(data.Name + ': ' + data['Execution Time'] + 'ms');
1277
+ });
1278
+ }
1279
+ console.groupEnd();
1280
+ }
1281
+ performance = [];
1282
+ },
1283
+ },
1284
+ invoke: function (query, passedArguments, context) {
1285
+ var
1286
+ object = instance,
1287
+ maxDepth,
1288
+ found,
1289
+ response
1290
+ ;
1291
+ passedArguments = passedArguments || queryArguments;
1292
+ context = context || element;
1293
+ if (typeof query === 'string' && object !== undefined) {
1294
+ query = query.split(/[ .]/);
1295
+ maxDepth = query.length - 1;
1296
+ $.each(query, function (depth, value) {
1297
+ var camelCaseValue = depth !== maxDepth
1298
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
1299
+ : query;
1300
+ if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
1301
+ object = object[camelCaseValue];
1302
+ } else if (object[camelCaseValue] !== undefined) {
1303
+ found = object[camelCaseValue];
1304
+
1305
+ return false;
1306
+ } else if ($.isPlainObject(object[value]) && (depth !== maxDepth)) {
1307
+ object = object[value];
1308
+ } else if (object[value] !== undefined) {
1309
+ found = object[value];
1310
+
1311
+ return false;
1312
+ } else {
1313
+ module.error(error.method, query);
1314
+
1315
+ return false;
1316
+ }
1317
+ });
1318
+ }
1319
+ if (isFunction(found)) {
1320
+ response = found.apply(context, passedArguments);
1321
+ } else if (found !== undefined) {
1322
+ response = found;
1323
+ }
1324
+ if (Array.isArray(returnedValue)) {
1325
+ returnedValue.push(response);
1326
+ } else if (returnedValue !== undefined) {
1327
+ returnedValue = [returnedValue, response];
1328
+ } else if (response !== undefined) {
1329
+ returnedValue = response;
1330
+ }
1331
+
1332
+ return found;
1333
+ },
1334
+ };
1335
+
1336
+ if (methodInvoked) {
1337
+ if (instance === undefined) {
1338
+ if (isFunction(settings.templates[query])) {
1339
+ settings.autoShow = true;
1340
+ settings.className.modal = settings.className.template;
1341
+ settings = $.extend(true, {}, settings, settings.templates[query].apply(module, queryArguments));
1342
+
1343
+ // reassign shortcuts
1344
+ className = settings.className;
1345
+ namespace = settings.namespace;
1346
+ fields = settings.fields;
1347
+ error = settings.error;
1348
+ }
1349
+ module.initialize();
1350
+ }
1351
+ if (!isFunction(settings.templates[query])) {
1352
+ module.invoke(query);
1353
+ }
1354
+ } else {
1355
+ if (instance !== undefined) {
1356
+ instance.invoke('destroy');
707
1357
  }
708
- });
709
- if(hideOk) {
710
- module.hideDimmer();
1358
+ module.initialize();
1359
+ returnedValue = $module;
711
1360
  }
712
- return hideOk;
713
- }
714
- },
1361
+ });
715
1362
 
716
- hideOthers: function(callback) {
717
- var
718
- $visibleModals = $otherModals.filter('.' + className.active + ', .' + className.animating)
719
- ;
720
- callback = $.isFunction(callback)
721
- ? callback
722
- : function(){}
723
- ;
724
- if( $visibleModals.length > 0 ) {
725
- module.debug('Hiding other modals', $otherModals);
726
- $visibleModals
727
- .modal('hide modal', callback, true)
728
- ;
729
- }
1363
+ return returnedValue !== undefined
1364
+ ? returnedValue
1365
+ : this;
1366
+ };
1367
+ $.modal = $.fn.modal;
1368
+
1369
+ $.fn.modal.settings = {
1370
+
1371
+ name: 'Modal',
1372
+ namespace: 'modal',
1373
+
1374
+ useFlex: 'auto',
1375
+ offset: 0,
1376
+
1377
+ silent: false,
1378
+ debug: false,
1379
+ verbose: false,
1380
+ performance: true,
1381
+
1382
+ observeChanges: false,
1383
+
1384
+ allowMultiple: false,
1385
+ detachable: true,
1386
+ closable: true,
1387
+ autofocus: true,
1388
+ restoreFocus: true,
1389
+ autoShow: false,
1390
+
1391
+ inverted: false,
1392
+ blurring: false,
1393
+
1394
+ centered: true,
1395
+
1396
+ dimmerSettings: {
1397
+ closable: false,
1398
+ useCSS: true,
730
1399
  },
731
1400
 
732
- others: {
733
- active: function() {
734
- return ($otherModals.filter('.' + className.active).length > 0);
735
- },
736
- animating: function() {
737
- return ($otherModals.filter('.' + className.animating).length > 0);
738
- }
1401
+ // whether to use keyboard shortcuts
1402
+ keyboardShortcuts: true,
1403
+
1404
+ context: 'body',
1405
+
1406
+ queue: false,
1407
+ duration: 500,
1408
+ transition: 'scale',
1409
+
1410
+ // padding with edge of page
1411
+ padding: 50,
1412
+ scrollbarWidth: 10,
1413
+
1414
+ // dynamic content
1415
+ title: '',
1416
+ content: '',
1417
+ class: '',
1418
+ classTitle: '',
1419
+ classContent: '',
1420
+ classActions: '',
1421
+ closeIcon: false,
1422
+ actions: false,
1423
+ preserveHTML: true,
1424
+
1425
+ fields: {
1426
+ class: 'class',
1427
+ text: 'text',
1428
+ icon: 'icon',
1429
+ click: 'click',
739
1430
  },
740
1431
 
1432
+ // called before show animation
1433
+ onShow: function () {},
741
1434
 
742
- add: {
743
- keyboardShortcuts: function() {
744
- module.verbose('Adding keyboard shortcuts');
745
- $document
746
- .on('keydown' + eventNamespace, module.event.keyboard)
747
- ;
748
- }
1435
+ // called after show animation
1436
+ onVisible: function () {},
1437
+
1438
+ // called before hide animation
1439
+ onHide: function () {
1440
+ return true;
749
1441
  },
750
1442
 
751
- save: {
752
- focus: function() {
753
- var
754
- $activeElement = $(document.activeElement),
755
- inCurrentModal = $activeElement.closest($module).length > 0
756
- ;
757
- if(!inCurrentModal) {
758
- $focusedElement = $(document.activeElement).blur();
759
- }
760
- },
761
- bodyMargin: function() {
762
- initialBodyMargin = $context.css((isBody ? 'margin-':'padding-')+(module.can.leftBodyScrollbar() ? 'left':'right'));
763
- var bodyMarginRightPixel = parseInt(initialBodyMargin.replace(/[^\d.]/g, '')),
764
- bodyScrollbarWidth = isBody ? window.innerWidth - document.documentElement.clientWidth : $context[0].offsetWidth - $context[0].clientWidth;
765
- tempBodyMargin = bodyMarginRightPixel + bodyScrollbarWidth;
766
- }
1443
+ // called after hide animation
1444
+ onHidden: false,
1445
+
1446
+ // called after approve selector match
1447
+ onApprove: function () {
1448
+ return true;
767
1449
  },
768
1450
 
769
- restore: {
770
- focus: function() {
771
- if($focusedElement && $focusedElement.length > 0 && settings.restoreFocus) {
772
- $focusedElement.focus();
773
- }
774
- },
775
- bodyMargin: function() {
776
- var position = module.can.leftBodyScrollbar() ? 'left':'right';
777
- $context.css((isBody ? 'margin-':'padding-')+position, initialBodyMargin);
778
- $context.find(selector.bodyFixed.replace('right',position)).each(function(){
779
- var el = $(this),
780
- attribute = el.css('position') === 'fixed' ? 'padding-'+position : position
781
- ;
782
- el.css(attribute, '');
783
- });
784
- }
1451
+ // called after deny selector match
1452
+ onDeny: function () {
1453
+ return true;
785
1454
  },
786
1455
 
787
- remove: {
788
- active: function() {
789
- $module.removeClass(className.active);
790
- },
791
- legacy: function() {
792
- $module.removeClass(className.legacy);
793
- },
794
- clickaway: function() {
795
- if (!settings.detachable) {
796
- $module
797
- .off('mousedown' + elementEventNamespace)
798
- ;
799
- }
800
- $dimmer
801
- .off('mousedown' + elementEventNamespace)
802
- ;
803
- $dimmer
804
- .off('mouseup' + elementEventNamespace)
805
- ;
806
- },
807
- dimmerStyles: function() {
808
- $dimmer.removeClass(className.inverted);
809
- $dimmable.removeClass(className.blurring);
810
- },
811
- bodyStyle: function() {
812
- if($context.attr('style') === '') {
813
- module.verbose('Removing style attribute');
814
- $context.removeAttr('style');
815
- }
816
- },
817
- screenHeight: function() {
818
- module.debug('Removing page height');
819
- $context
820
- .css('height', '')
821
- ;
822
- module.remove.bodyStyle()
823
- },
824
- keyboardShortcuts: function() {
825
- module.verbose('Removing keyboard shortcuts');
826
- $document
827
- .off('keydown' + eventNamespace)
828
- ;
829
- },
830
- scrolling: function() {
831
- if(!keepScrollingClass) {
832
- $dimmable.removeClass(className.scrolling);
833
- }
834
- $module.removeClass(className.scrolling);
835
- }
1456
+ keys: {
1457
+ space: 32,
1458
+ enter: 13,
1459
+ escape: 27,
1460
+ tab: 9,
836
1461
  },
837
1462
 
838
- cacheSizes: function() {
839
- $module.addClass(className.loading);
840
- var
841
- scrollHeight = $module.prop('scrollHeight'),
842
- modalWidth = $module.outerWidth(),
843
- modalHeight = $module.outerHeight()
844
- ;
845
- if(module.cache.pageHeight === undefined || modalHeight !== 0) {
846
- $.extend(module.cache, {
847
- pageHeight : $document.outerHeight(),
848
- width : modalWidth,
849
- height : modalHeight + settings.offset,
850
- scrollHeight : scrollHeight + settings.offset,
851
- contextHeight : isBody
852
- ? $window.height()
853
- : $dimmable.height(),
854
- });
855
- module.cache.topOffset = -(module.cache.height / 2);
856
- }
857
- $module.removeClass(className.loading);
858
- module.debug('Caching modal and container sizes', module.cache);
1463
+ selector: {
1464
+ title: '> .header',
1465
+ content: '> .content',
1466
+ actions: '> .actions',
1467
+ close: '> .close',
1468
+ closeIcon: '> .close',
1469
+ approve: '.actions .positive, .actions .approve, .actions .ok',
1470
+ deny: '.actions .negative, .actions .deny, .actions .cancel',
1471
+ modal: '.ui.modal',
1472
+ dimmer: '> .ui.dimmer',
1473
+ bodyFixed: '> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar, > .ui.fixed.nag, > .ui.fixed.nag > .close',
1474
+ prompt: '.ui.input > input',
859
1475
  },
860
- helpers: {
861
- deQuote: function(string) {
862
- return String(string).replace(/"/g,"");
863
- },
864
- escape: function(string, preserveHTML) {
865
- if (preserveHTML){
866
- return string;
867
- }
868
- var
869
- badChars = /[<>"'`]/g,
870
- shouldEscape = /[&<>"'`]/,
871
- escape = {
872
- "<": "&lt;",
873
- ">": "&gt;",
874
- '"': "&quot;",
875
- "'": "&#x27;",
876
- "`": "&#x60;"
877
- },
878
- escapedChar = function(chr) {
879
- return escape[chr];
880
- }
881
- ;
882
- if(shouldEscape.test(string)) {
883
- string = string.replace(/&(?![a-z0-9#]{1,12};)/gi, "&amp;");
884
- return string.replace(badChars, escapedChar);
885
- }
886
- return string;
887
- }
1476
+ error: {
1477
+ dimmer: 'UI Dimmer, a required component is not included in this page',
1478
+ method: 'The method you called is not defined.',
1479
+ notFound: 'The element you specified could not be found',
888
1480
  },
889
- can: {
890
- leftBodyScrollbar: function(){
891
- if(module.cache.leftBodyScrollbar === undefined) {
892
- module.cache.leftBodyScrollbar = module.is.rtl() && ((module.is.iframe && !module.is.firefox()) || module.is.safari() || module.is.edge() || module.is.ie());
893
- }
894
- return module.cache.leftBodyScrollbar;
895
- },
896
- useFlex: function() {
897
- if (settings.useFlex === 'auto') {
898
- return settings.detachable && !module.is.ie();
899
- }
900
- if(settings.useFlex && module.is.ie()) {
901
- module.debug('useFlex true is not supported in IE');
902
- } else if(settings.useFlex && !settings.detachable) {
903
- module.debug('useFlex true in combination with detachable false is not supported');
904
- }
905
- return settings.useFlex;
906
- },
907
- fit: function() {
908
- var
909
- contextHeight = module.cache.contextHeight,
910
- verticalCenter = module.cache.contextHeight / 2,
911
- topOffset = module.cache.topOffset,
912
- scrollHeight = module.cache.scrollHeight,
913
- height = module.cache.height,
914
- paddingHeight = settings.padding,
915
- startPosition = (verticalCenter + topOffset)
916
- ;
917
- return (scrollHeight > height)
918
- ? (startPosition + scrollHeight + paddingHeight < contextHeight)
919
- : (height + (paddingHeight * 2) < contextHeight)
920
- ;
921
- }
1481
+ className: {
1482
+ active: 'active',
1483
+ animating: 'animating',
1484
+ blurring: 'blurring',
1485
+ inverted: 'inverted',
1486
+ legacy: 'legacy',
1487
+ loading: 'loading',
1488
+ scrolling: 'scrolling',
1489
+ undetached: 'undetached',
1490
+ front: 'front',
1491
+ close: 'close icon',
1492
+ button: 'ui button',
1493
+ modal: 'ui modal',
1494
+ title: 'header',
1495
+ content: 'content',
1496
+ actions: 'actions',
1497
+ template: 'ui tiny modal',
1498
+ ok: 'positive',
1499
+ cancel: 'negative',
1500
+ prompt: 'ui fluid input',
1501
+ innerDimmer: 'ui inverted dimmer',
922
1502
  },
923
- has: {
924
- configActions: function () {
925
- return Array.isArray(settings.actions) && settings.actions.length > 0;
926
- },
927
- scrollbar: function() {
928
- return isBody || $context.css('overflow-y') !== 'hidden';
929
- }
1503
+ text: {
1504
+ ok: 'Ok',
1505
+ cancel: 'Cancel',
1506
+ close: 'Close',
930
1507
  },
931
- is: {
932
- active: function() {
933
- return $module.hasClass(className.active);
934
- },
935
- ie: function() {
936
- if(module.cache.isIE === undefined) {
937
- var
938
- isIE11 = (!(window.ActiveXObject) && 'ActiveXObject' in window),
939
- isIE = ('ActiveXObject' in window)
940
- ;
941
- module.cache.isIE = (isIE11 || isIE);
942
- }
943
- return module.cache.isIE;
944
- },
945
- animating: function() {
946
- return $module.transition('is supported')
947
- ? $module.transition('is animating')
948
- : $module.is(':visible')
949
- ;
950
- },
951
- scrolling: function() {
952
- return $dimmable.hasClass(className.scrolling);
953
- },
954
- modernBrowser: function() {
955
- // appName for IE11 reports 'Netscape' can no longer use
956
- return !(window.ActiveXObject || 'ActiveXObject' in window);
957
- },
958
- rtl: function() {
959
- if(module.cache.isRTL === undefined) {
960
- module.cache.isRTL = $module.attr('dir') === 'rtl' || $module.css('direction') === 'rtl' || $body.attr('dir') === 'rtl' || $body.css('direction') === 'rtl' || $context.attr('dir') === 'rtl' || $context.css('direction') === 'rtl';
961
- }
962
- return module.cache.isRTL;
963
- },
964
- safari: function() {
965
- if(module.cache.isSafari === undefined) {
966
- module.cache.isSafari = /constructor/i.test(window.HTMLElement) || !!window.ApplePaySession;
967
- }
968
- return module.cache.isSafari;
969
- },
970
- edge: function(){
971
- if(module.cache.isEdge === undefined) {
972
- module.cache.isEdge = !!window.setImmediate && !module.is.ie();
973
- }
974
- return module.cache.isEdge;
975
- },
976
- firefox: function(){
977
- if(module.cache.isFirefox === undefined) {
978
- module.cache.isFirefox = !!window.InstallTrigger;
979
- }
980
- return module.cache.isFirefox;
981
- },
982
- iframe: function() {
983
- return !(self === top);
984
- }
1508
+ };
1509
+
1510
+ $.fn.modal.settings.templates = {
1511
+ getArguments: function (args) {
1512
+ var queryArguments = [].slice.call(args);
1513
+ if ($.isPlainObject(queryArguments[0])) {
1514
+ return $.extend({
1515
+ handler: function () {},
1516
+ content: '',
1517
+ title: '',
1518
+ }, queryArguments[0]);
1519
+ }
1520
+ if (!isFunction(queryArguments[queryArguments.length - 1])) {
1521
+ queryArguments.push(function () {});
1522
+ }
1523
+
1524
+ return {
1525
+ handler: queryArguments.pop(),
1526
+ content: queryArguments.pop() || '',
1527
+ title: queryArguments.pop() || '',
1528
+ };
985
1529
  },
986
-
987
- set: {
988
- autofocus: function() {
1530
+ alert: function () {
989
1531
  var
990
- $autofocus = $inputs.filter('[autofocus]'),
991
- $input = ($autofocus.length > 0)
992
- ? $autofocus.first()
993
- : ($inputs.length > 1 ? $inputs.filter(':not(i.close)') : $inputs).first()
994
- ;
995
- if($input.length > 0) {
996
- $input.focus();
997
- }
998
- },
999
- bodyMargin: function() {
1000
- var position = module.can.leftBodyScrollbar() ? 'left':'right';
1001
- if(settings.detachable || module.can.fit()) {
1002
- $context.css((isBody ? 'margin-':'padding-')+position, tempBodyMargin + 'px');
1003
- }
1004
- $context.find(selector.bodyFixed.replace('right',position)).each(function(){
1005
- var el = $(this),
1006
- attribute = el.css('position') === 'fixed' ? 'padding-'+position : position
1007
- ;
1008
- el.css(attribute, 'calc(' + el.css(attribute) + ' + ' + tempBodyMargin + 'px)');
1009
- });
1010
- },
1011
- clickaway: function() {
1012
- if (!settings.detachable) {
1013
- $module
1014
- .on('mousedown' + elementEventNamespace, module.event.mousedown)
1015
- ;
1016
- }
1017
- $dimmer
1018
- .on('mousedown' + elementEventNamespace, module.event.mousedown)
1019
- ;
1020
- $dimmer
1021
- .on('mouseup' + elementEventNamespace, module.event.mouseup)
1532
+ settings = this.get.settings(),
1533
+ args = settings.templates.getArguments(arguments),
1534
+ approveFn = args.handler
1022
1535
  ;
1023
- },
1024
- dimmerSettings: function() {
1025
- if($.fn.dimmer === undefined) {
1026
- module.error(error.dimmer);
1027
- return;
1028
- }
1536
+
1537
+ return {
1538
+ title: args.title,
1539
+ content: args.content,
1540
+ onApprove: approveFn,
1541
+ actions: [{
1542
+ text: settings.text.ok,
1543
+ class: settings.className.ok,
1544
+ click: approveFn,
1545
+ }],
1546
+ };
1547
+ },
1548
+ confirm: function () {
1029
1549
  var
1030
- defaultSettings = {
1031
- debug : settings.debug,
1032
- dimmerName : 'modals',
1033
- closable : 'auto',
1034
- useFlex : module.can.useFlex(),
1035
- duration : {
1036
- show : settings.transition.showDuration || settings.duration,
1037
- hide : settings.transition.hideDuration || settings.duration
1550
+ settings = this.get.settings(),
1551
+ args = settings.templates.getArguments(arguments),
1552
+ approveFn = function () {
1553
+ args.handler(true);
1554
+ },
1555
+ denyFn = function () {
1556
+ args.handler(false);
1038
1557
  }
1039
- },
1040
- dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
1041
1558
  ;
1042
- if(settings.inverted) {
1043
- dimmerSettings.variation = (dimmerSettings.variation !== undefined)
1044
- ? dimmerSettings.variation + ' inverted'
1045
- : 'inverted'
1046
- ;
1047
- }
1048
- $context.dimmer('setting', dimmerSettings);
1049
- },
1050
- dimmerStyles: function() {
1051
- if(settings.inverted) {
1052
- $dimmer.addClass(className.inverted);
1053
- }
1054
- else {
1055
- $dimmer.removeClass(className.inverted);
1056
- }
1057
- if(settings.blurring) {
1058
- $dimmable.addClass(className.blurring);
1059
- }
1060
- else {
1061
- $dimmable.removeClass(className.blurring);
1062
- }
1063
- },
1064
- modalOffset: function() {
1065
- if (!settings.detachable) {
1066
- var canFit = module.can.fit();
1067
- $module
1068
- .css({
1069
- top: (!$module.hasClass('aligned') && canFit)
1070
- ? $document.scrollTop() + (module.cache.contextHeight - module.cache.height) / 2
1071
- : !canFit || $module.hasClass('top')
1072
- ? $document.scrollTop() + settings.padding
1073
- : $document.scrollTop() + (module.cache.contextHeight - module.cache.height - settings.padding),
1074
- marginLeft: -(module.cache.width / 2)
1075
- })
1076
- ;
1077
- } else {
1078
- $module
1079
- .css({
1080
- marginTop: (!$module.hasClass('aligned') && module.can.fit())
1081
- ? -(module.cache.height / 2)
1082
- : settings.padding / 2,
1083
- marginLeft: -(module.cache.width / 2)
1084
- })
1085
- ;
1086
- }
1087
- module.verbose('Setting modal offset for legacy mode');
1088
- },
1089
- screenHeight: function() {
1090
- if( module.can.fit() ) {
1091
- $context.css('height', '');
1092
- }
1093
- else if(!$module.hasClass('bottom')) {
1094
- module.debug('Modal is taller than page content, resizing page height');
1095
- $context
1096
- .css('height', module.cache.height + (settings.padding * 2) )
1097
- ;
1098
- }
1099
- },
1100
- active: function() {
1101
- $module.addClass(className.active + ' ' + className.front);
1102
- $otherModals.filter('.' + className.active).removeClass(className.front);
1103
- },
1104
- scrolling: function() {
1105
- $dimmable.addClass(className.scrolling);
1106
- $module.addClass(className.scrolling);
1107
- module.unbind.scrollLock();
1108
- },
1109
- legacy: function() {
1110
- $module.addClass(className.legacy);
1111
- },
1112
- type: function() {
1113
- if(module.can.fit()) {
1114
- module.verbose('Modal fits on screen');
1115
- if(!module.others.active() && !module.others.animating()) {
1116
- module.remove.scrolling();
1117
- module.bind.scrollLock();
1118
- }
1119
- }
1120
- else if (!$module.hasClass('bottom')){
1121
- module.verbose('Modal cannot fit on screen setting to scrolling');
1122
- module.set.scrolling();
1123
- } else {
1124
- module.verbose('Bottom aligned modal not fitting on screen is unsupported for scrolling');
1125
- }
1126
- },
1127
- undetached: function() {
1128
- $dimmable.addClass(className.undetached);
1129
- }
1130
- },
1131
1559
 
1132
- setting: function(name, value) {
1133
- module.debug('Changing setting', name, value);
1134
- if( $.isPlainObject(name) ) {
1135
- $.extend(true, settings, name);
1136
- }
1137
- else if(value !== undefined) {
1138
- if($.isPlainObject(settings[name])) {
1139
- $.extend(true, settings[name], value);
1140
- }
1141
- else {
1142
- settings[name] = value;
1143
- }
1144
- }
1145
- else {
1146
- return settings[name];
1147
- }
1148
- },
1149
- internal: function(name, value) {
1150
- if( $.isPlainObject(name) ) {
1151
- $.extend(true, module, name);
1152
- }
1153
- else if(value !== undefined) {
1154
- module[name] = value;
1155
- }
1156
- else {
1157
- return module[name];
1158
- }
1159
- },
1160
- debug: function() {
1161
- if(!settings.silent && settings.debug) {
1162
- if(settings.performance) {
1163
- module.performance.log(arguments);
1164
- }
1165
- else {
1166
- module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
1167
- module.debug.apply(console, arguments);
1168
- }
1169
- }
1170
- },
1171
- verbose: function() {
1172
- if(!settings.silent && settings.verbose && settings.debug) {
1173
- if(settings.performance) {
1174
- module.performance.log(arguments);
1175
- }
1176
- else {
1177
- module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
1178
- module.verbose.apply(console, arguments);
1179
- }
1180
- }
1560
+ return {
1561
+ title: args.title,
1562
+ content: args.content,
1563
+ onApprove: approveFn,
1564
+ onDeny: denyFn,
1565
+ actions: [{
1566
+ text: settings.text.ok,
1567
+ class: settings.className.ok,
1568
+ click: approveFn,
1569
+ }, {
1570
+ text: settings.text.cancel,
1571
+ class: settings.className.cancel,
1572
+ click: denyFn,
1573
+ }],
1574
+ };
1181
1575
  },
1182
- error: function() {
1183
- if(!settings.silent) {
1184
- module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
1185
- module.error.apply(console, arguments);
1186
- }
1187
- },
1188
- performance: {
1189
- log: function(message) {
1190
- var
1191
- currentTime,
1192
- executionTime,
1193
- previousTime
1194
- ;
1195
- if(settings.performance) {
1196
- currentTime = new Date().getTime();
1197
- previousTime = time || currentTime;
1198
- executionTime = currentTime - previousTime;
1199
- time = currentTime;
1200
- performance.push({
1201
- 'Name' : message[0],
1202
- 'Arguments' : [].slice.call(message, 1) || '',
1203
- 'Element' : element,
1204
- 'Execution Time' : executionTime
1205
- });
1206
- }
1207
- clearTimeout(module.performance.timer);
1208
- module.performance.timer = setTimeout(module.performance.display, 500);
1209
- },
1210
- display: function() {
1576
+ prompt: function () {
1211
1577
  var
1212
- title = settings.name + ':',
1213
- totalTime = 0
1578
+ $this = this,
1579
+ settings = this.get.settings(),
1580
+ args = settings.templates.getArguments(arguments),
1581
+ input = $($.parseHTML(args.content)).filter('.ui.input'),
1582
+ approveFn = function () {
1583
+ var
1584
+ settings = $this.get.settings(),
1585
+ inputField = $this.get.element().find(settings.selector.prompt)[0]
1586
+ ;
1587
+ args.handler($(inputField).val());
1588
+ },
1589
+ denyFn = function () {
1590
+ args.handler(null);
1591
+ }
1214
1592
  ;
1215
- time = false;
1216
- clearTimeout(module.performance.timer);
1217
- $.each(performance, function(index, data) {
1218
- totalTime += data['Execution Time'];
1219
- });
1220
- title += ' ' + totalTime + 'ms';
1221
- if(moduleSelector) {
1222
- title += ' \'' + moduleSelector + '\'';
1223
- }
1224
- if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
1225
- console.groupCollapsed(title);
1226
- if(console.table) {
1227
- console.table(performance);
1228
- }
1229
- else {
1230
- $.each(performance, function(index, data) {
1231
- console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
1232
- });
1233
- }
1234
- console.groupEnd();
1235
- }
1236
- performance = [];
1237
- }
1593
+ if (input.length === 0) {
1594
+ args.content += '<p><div class="' + this.helpers.deQuote(settings.className.prompt) + '"><input placeholder="' + this.helpers.deQuote(args.placeholder || '') + '" type="text" value="' + this.helpers.deQuote(args.defaultValue || '') + '"></div></p>';
1595
+ }
1596
+
1597
+ return {
1598
+ title: args.title,
1599
+ content: args.content,
1600
+ onApprove: approveFn,
1601
+ onDeny: denyFn,
1602
+ actions: [{
1603
+ text: settings.text.ok,
1604
+ class: settings.className.ok,
1605
+ click: approveFn,
1606
+ }, {
1607
+ text: settings.text.cancel,
1608
+ class: settings.className.cancel,
1609
+ click: denyFn,
1610
+ }],
1611
+ };
1238
1612
  },
1239
- invoke: function(query, passedArguments, context) {
1240
- var
1241
- object = instance,
1242
- maxDepth,
1243
- found,
1244
- response
1245
- ;
1246
- passedArguments = passedArguments || queryArguments;
1247
- context = context || element;
1248
- if(typeof query == 'string' && object !== undefined) {
1249
- query = query.split(/[\. ]/);
1250
- maxDepth = query.length - 1;
1251
- $.each(query, function(depth, value) {
1252
- var camelCaseValue = (depth != maxDepth)
1253
- ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
1254
- : query
1255
- ;
1256
- if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
1257
- object = object[camelCaseValue];
1258
- }
1259
- else if( object[camelCaseValue] !== undefined ) {
1260
- found = object[camelCaseValue];
1261
- return false;
1262
- }
1263
- else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
1264
- object = object[value];
1265
- }
1266
- else if( object[value] !== undefined ) {
1267
- found = object[value];
1268
- return false;
1269
- }
1270
- else {
1271
- return false;
1272
- }
1273
- });
1274
- }
1275
- if ( $.isFunction( found ) ) {
1276
- response = found.apply(context, passedArguments);
1277
- }
1278
- else if(found !== undefined) {
1279
- response = found;
1280
- }
1281
- if(Array.isArray(returnedValue)) {
1282
- returnedValue.push(response);
1283
- }
1284
- else if(returnedValue !== undefined) {
1285
- returnedValue = [returnedValue, response];
1286
- }
1287
- else if(response !== undefined) {
1288
- returnedValue = response;
1289
- }
1290
- return found;
1291
- }
1292
- };
1293
-
1294
- if(methodInvoked) {
1295
- if(instance === undefined) {
1296
- if ($.isFunction(settings.templates[query])) {
1297
- settings.autoShow = true;
1298
- settings.className.modal = settings.className.template;
1299
- settings = $.extend(true, {}, settings, settings.templates[query].apply(module ,queryArguments));
1300
-
1301
- // reassign shortcuts
1302
- className = settings.className;
1303
- namespace = settings.namespace;
1304
- fields = settings.fields;
1305
- error = settings.error;
1306
- }
1307
- module.initialize();
1308
- }
1309
- if (!$.isFunction(settings.templates[query])) {
1310
- module.invoke(query);
1311
- }
1312
- }
1313
- else {
1314
- if(instance !== undefined) {
1315
- instance.invoke('destroy');
1316
- }
1317
- module.initialize();
1318
- returnedValue = $module;
1319
- }
1320
- })
1321
- ;
1322
-
1323
- return (returnedValue !== undefined)
1324
- ? returnedValue
1325
- : this
1326
- ;
1327
- };
1328
-
1329
- $.fn.modal.settings = {
1330
-
1331
- name : 'Modal',
1332
- namespace : 'modal',
1333
-
1334
- useFlex : 'auto',
1335
- offset : 0,
1336
-
1337
- silent : false,
1338
- debug : false,
1339
- verbose : false,
1340
- performance : true,
1341
-
1342
- observeChanges : false,
1343
-
1344
- allowMultiple : false,
1345
- detachable : true,
1346
- closable : true,
1347
- autofocus : true,
1348
- restoreFocus : true,
1349
- autoShow : false,
1350
-
1351
- inverted : false,
1352
- blurring : false,
1353
-
1354
- centered : true,
1355
-
1356
- dimmerSettings : {
1357
- closable : false,
1358
- useCSS : true
1359
- },
1360
-
1361
- // whether to use keyboard shortcuts
1362
- keyboardShortcuts: true,
1363
-
1364
- context : 'body',
1365
-
1366
- queue : false,
1367
- duration : 500,
1368
- transition : 'scale',
1369
-
1370
- // padding with edge of page
1371
- padding : 50,
1372
- scrollbarWidth: 10,
1373
-
1374
- //dynamic content
1375
- title : '',
1376
- content : '',
1377
- class : '',
1378
- classTitle : '',
1379
- classContent : '',
1380
- classActions : '',
1381
- closeIcon : false,
1382
- actions : false,
1383
- preserveHTML : true,
1384
-
1385
- fields : {
1386
- class : 'class',
1387
- text : 'text',
1388
- icon : 'icon',
1389
- click : 'click'
1390
- },
1391
-
1392
- // called before show animation
1393
- onShow : function(){},
1394
-
1395
- // called after show animation
1396
- onVisible : function(){},
1397
-
1398
- // called before hide animation
1399
- onHide : function(){ return true; },
1400
-
1401
- // called after hide animation
1402
- onHidden : false,
1403
-
1404
- // called after approve selector match
1405
- onApprove : function(){ return true; },
1406
-
1407
- // called after deny selector match
1408
- onDeny : function(){ return true; },
1409
-
1410
- keys : {
1411
- space : 32,
1412
- enter : 13,
1413
- escape : 27,
1414
- tab : 9,
1415
- },
1416
-
1417
- selector : {
1418
- title : '> .header',
1419
- content : '> .content',
1420
- actions : '> .actions',
1421
- close : '> .close',
1422
- closeIcon: '> .close',
1423
- approve : '.actions .positive, .actions .approve, .actions .ok',
1424
- deny : '.actions .negative, .actions .deny, .actions .cancel',
1425
- modal : '.ui.modal',
1426
- dimmer : '> .ui.dimmer',
1427
- bodyFixed: '> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar, > .ui.fixed.nag, > .ui.fixed.nag > .close',
1428
- prompt : '.ui.input > input'
1429
- },
1430
- error : {
1431
- dimmer : 'UI Dimmer, a required component is not included in this page',
1432
- method : 'The method you called is not defined.',
1433
- notFound : 'The element you specified could not be found'
1434
- },
1435
- className : {
1436
- active : 'active',
1437
- animating : 'animating',
1438
- blurring : 'blurring',
1439
- inverted : 'inverted',
1440
- legacy : 'legacy',
1441
- loading : 'loading',
1442
- scrolling : 'scrolling',
1443
- undetached : 'undetached',
1444
- front : 'front',
1445
- close : 'close icon',
1446
- button : 'ui button',
1447
- modal : 'ui modal',
1448
- title : 'header',
1449
- content : 'content',
1450
- actions : 'actions',
1451
- template : 'ui tiny modal',
1452
- ok : 'positive',
1453
- cancel : 'negative',
1454
- prompt : 'ui fluid input',
1455
- innerDimmer: 'ui inverted dimmer'
1456
- },
1457
- text: {
1458
- ok : 'Ok',
1459
- cancel: 'Cancel',
1460
- close : 'Close'
1461
- }
1462
- };
1463
-
1464
- $.fn.modal.settings.templates = {
1465
- getArguments: function(args) {
1466
- var queryArguments = [].slice.call(args);
1467
- if($.isPlainObject(queryArguments[0])){
1468
- return $.extend({
1469
- handler:function(){},
1470
- content:'',
1471
- title: ''
1472
- }, queryArguments[0]);
1473
- } else {
1474
- if(!$.isFunction(queryArguments[queryArguments.length-1])) {
1475
- queryArguments.push(function() {});
1476
- }
1477
- return {
1478
- handler: queryArguments.pop(),
1479
- content: queryArguments.pop() || '',
1480
- title: queryArguments.pop() || ''
1481
- };
1482
- }
1483
- },
1484
- alert: function () {
1485
- var settings = this.get.settings(),
1486
- args = settings.templates.getArguments(arguments),
1487
- approveFn = args.handler
1488
- ;
1489
- return {
1490
- title : args.title,
1491
- content: args.content,
1492
- onApprove: approveFn,
1493
- actions: [{
1494
- text : settings.text.ok,
1495
- class: settings.className.ok,
1496
- click: approveFn
1497
- }]
1498
- }
1499
- },
1500
- confirm: function () {
1501
- var settings = this.get.settings(),
1502
- args = settings.templates.getArguments(arguments),
1503
- approveFn = function(){args.handler(true)},
1504
- denyFn = function(){args.handler(false)}
1505
- ;
1506
- return {
1507
- title : args.title,
1508
- content: args.content,
1509
- onApprove: approveFn,
1510
- onDeny: denyFn,
1511
- actions: [{
1512
- text : settings.text.ok,
1513
- class: settings.className.ok,
1514
- click: approveFn
1515
- },{
1516
- text: settings.text.cancel,
1517
- class: settings.className.cancel,
1518
- click: denyFn
1519
- }]
1520
- }
1521
- },
1522
- prompt: function () {
1523
- var $this = this,
1524
- settings = this.get.settings(),
1525
- args = settings.templates.getArguments(arguments),
1526
- input = $($.parseHTML(args.content)).filter('.ui.input'),
1527
- approveFn = function(){
1528
- var settings = $this.get.settings(),
1529
- inputField = $this.get.element().find(settings.selector.prompt)[0]
1530
- ;
1531
- args.handler($(inputField).val());
1532
- },
1533
- denyFn = function(){args.handler(null)}
1534
- ;
1535
- if (input.length === 0) {
1536
- args.content += '<p><div class="'+this.helpers.deQuote(settings.className.prompt)+'"><input placeholder="'+this.helpers.deQuote(args.placeholder || '')+'" type="text" value="'+this.helpers.deQuote(args.defaultValue || '')+'"></div></p>';
1537
- }
1538
- return {
1539
- title : args.title,
1540
- content: args.content,
1541
- onApprove: approveFn,
1542
- onDeny: denyFn,
1543
- actions: [{
1544
- text: settings.text.ok,
1545
- class: settings.className.ok,
1546
- click: approveFn
1547
- },{
1548
- text: settings.text.cancel,
1549
- class: settings.className.cancel,
1550
- click: denyFn
1551
- }]
1552
- }
1553
- }
1554
- }
1555
-
1556
- })( jQuery, window, document );
1613
+ };
1614
+ })(jQuery, window, document);