rails-active-ui 0.1.0

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