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,916 @@
1
+ /*!
2
+ * # Fomantic-UI 2.9.4 - Toast
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.toast = function (...args) {
23
+ const $body = $('body');
24
+ const $allModules = isFunction(this)
25
+ ? $body
26
+ : $(this);
27
+
28
+ let time = Date.now();
29
+ let performance = [];
30
+
31
+ const parameters = args[0];
32
+ const methodInvoked = typeof parameters === 'string';
33
+ const queryArguments = args.slice(1);
34
+ const contextCheck = function (context, win) {
35
+ let $context;
36
+ if ([window, document].includes(context)) {
37
+ $context = $(context);
38
+ } else {
39
+ $context = $(win.document).find(context);
40
+ if ($context.length === 0) {
41
+ $context = win.frameElement ? contextCheck(context, win.parent) : $body;
42
+ }
43
+ }
44
+
45
+ return $context;
46
+ };
47
+ let returnedValue;
48
+ $allModules.each(function () {
49
+ const settings = $.isPlainObject(parameters)
50
+ ? $.extend(true, {}, $.fn.toast.settings, parameters)
51
+ : $.extend({}, $.fn.toast.settings);
52
+
53
+ const className = settings.className;
54
+ const selector = settings.selector;
55
+ const error = settings.error;
56
+ const namespace = settings.namespace;
57
+ const fields = settings.fields;
58
+
59
+ const eventNamespace = '.' + namespace;
60
+ const moduleNamespace = namespace + '-module';
61
+
62
+ let $module = $(this);
63
+ let $toastBox;
64
+ let $toast;
65
+ let $actions;
66
+ let $progress;
67
+ let $progressBar;
68
+ let $animationObject;
69
+ let $close;
70
+ const $context = settings.context ? contextCheck(settings.context, window) : $body;
71
+
72
+ const isToastComponent = $module.hasClass('toast') || $module.hasClass('message') || $module.hasClass('card');
73
+
74
+ let element = this;
75
+ let instance = isToastComponent ? $module.data(moduleNamespace) : undefined;
76
+
77
+ let id;
78
+ const module = {
79
+
80
+ initialize: function () {
81
+ module.verbose('Initializing element');
82
+ module.create.id();
83
+ if (!module.has.container()) {
84
+ module.create.container();
85
+ }
86
+ if (isToastComponent || settings.message !== '' || settings.title !== '' || module.get.iconClass() !== '' || settings.showImage || module.has.configActions()) {
87
+ if (typeof settings.showProgress !== 'string' || ![className.top, className.bottom].includes(settings.showProgress)) {
88
+ settings.showProgress = false;
89
+ }
90
+ module.create.toast();
91
+ if (settings.closeOnClick && (settings.closeIcon || $($toast).find(selector.input).length > 0 || module.has.configActions())) {
92
+ settings.closeOnClick = false;
93
+ }
94
+ if (!settings.closeOnClick) {
95
+ $toastBox.addClass(className.unclickable);
96
+ }
97
+ module.bind.events();
98
+ }
99
+ module.instantiate();
100
+ if ($toastBox) {
101
+ module.show();
102
+ }
103
+ },
104
+
105
+ instantiate: function () {
106
+ module.verbose('Storing instance of toast');
107
+ instance = module;
108
+ $module
109
+ .data(moduleNamespace, instance);
110
+ },
111
+
112
+ destroy: function () {
113
+ if ($toastBox) {
114
+ module.debug('Removing toast', $toastBox);
115
+ module.unbind.events();
116
+ settings.onRemove.call($toastBox, element);
117
+ $toastBox.remove();
118
+ $toastBox = undefined;
119
+ $toast = undefined;
120
+ $animationObject = undefined;
121
+ $progress = undefined;
122
+ $progressBar = undefined;
123
+ $close = undefined;
124
+ }
125
+ $module
126
+ .removeData(moduleNamespace);
127
+ },
128
+
129
+ show: function (callback = function () {}) {
130
+ if (settings.onShow.call($toastBox, element) === false) {
131
+ module.debug('onShow callback returned false, cancelling toast animation');
132
+
133
+ return;
134
+ }
135
+ module.debug('Showing toast');
136
+ module.animate.show(callback);
137
+ },
138
+
139
+ close: function (callback = function () {}) {
140
+ if (settings.onHide.call($toastBox, element) === false) {
141
+ module.debug('onHide callback returned false, cancelling toast animation');
142
+
143
+ return;
144
+ }
145
+ module.debug('Closing toast');
146
+ module.remove.visible();
147
+ module.unbind.events();
148
+ module.animate.close(callback);
149
+ },
150
+
151
+ create: {
152
+ container: function () {
153
+ module.verbose('Creating container');
154
+ $context.append($('<div/>', {
155
+ class: settings.position + ' ' + className.container + ' '
156
+ + (settings.horizontal ? className.horizontal : '') + ' '
157
+ + (settings.context && settings.context !== 'body' ? className.absolute : ''),
158
+ }));
159
+ },
160
+ id: function () {
161
+ id = (Math.random().toString(16) + '000000000').slice(2, 10);
162
+ module.verbose('Creating unique id for element', id);
163
+ },
164
+ toast: function () {
165
+ $toastBox = $('<div/>', { class: className.box });
166
+ const iconClass = module.get.iconClass();
167
+ if (!isToastComponent) {
168
+ module.verbose('Creating toast');
169
+ $toast = $('<div/>', { role: 'alert' });
170
+ const $content = $('<div/>', { class: className.content });
171
+ if (iconClass !== '') {
172
+ $toast.append($('<i/>', { class: iconClass + ' ' + className.icon }));
173
+ }
174
+
175
+ if (settings.showImage) {
176
+ $toast.append($('<img>', {
177
+ class: className.image + ' ' + settings.classImage,
178
+ src: settings.showImage,
179
+ alt: settings.alt || '',
180
+ }));
181
+ }
182
+ if (settings.title !== '') {
183
+ const titleId = '_' + module.get.id() + 'title';
184
+ $toast.attr('aria-labelledby', titleId);
185
+ $content.append($('<div/>', {
186
+ class: className.title,
187
+ id: titleId,
188
+ html: module.helpers.escape(settings.title, settings),
189
+ }));
190
+ }
191
+ const descId = '_' + module.get.id() + 'desc';
192
+ $toast.attr('aria-describedby', descId);
193
+ $content.append($('<div/>', {
194
+ class: className.message,
195
+ id: descId,
196
+ html: module.helpers.escape(settings.message, settings),
197
+ }));
198
+
199
+ $toast
200
+ .addClass(settings.class + ' ' + className.toast)
201
+ .append($content);
202
+ $toast.css('opacity', String(settings.opacity));
203
+ if (settings.closeIcon) {
204
+ $close = $('<i/>', {
205
+ class: className.close + ' ' + (typeof settings.closeIcon === 'string' ? settings.closeIcon : ''),
206
+ role: 'button',
207
+ tabindex: 0,
208
+ 'aria-label': settings.text.close,
209
+ });
210
+ if ($close.hasClass(className.left)) {
211
+ $toast.prepend($close);
212
+ } else {
213
+ $toast.append($close);
214
+ }
215
+ }
216
+ } else {
217
+ $toast = settings.cloneModule ? $module.clone().removeAttr('id') : $module;
218
+ $close = $toast.find('> i' + module.helpers.toClass(className.close));
219
+ settings.closeIcon = $close.length > 0;
220
+ if (iconClass !== '') {
221
+ $toast.find(selector.icon).attr('class', iconClass + ' ' + className.icon);
222
+ }
223
+ if (settings.showImage) {
224
+ $toast.find(selector.image).attr('src', settings.showImage).attr('alt', settings.alt || '');
225
+ }
226
+ if (settings.title !== '') {
227
+ $toast.find(selector.title).html(module.helpers.escape(settings.title, settings));
228
+ }
229
+ if (settings.message !== '') {
230
+ $toast.find(selector.message).html(module.helpers.escape(settings.message, settings));
231
+ }
232
+ }
233
+ if ($toast.hasClass(className.compact)) {
234
+ settings.compact = true;
235
+ }
236
+ if ($toast.hasClass('card')) {
237
+ settings.compact = false;
238
+ }
239
+ $actions = $toast.find('.actions');
240
+ if (module.has.configActions()) {
241
+ if ($actions.length === 0) {
242
+ $actions = $('<div/>', { class: className.actions + ' ' + (settings.classActions || '') }).appendTo($toast);
243
+ }
244
+ if ($toast.hasClass('card') && !$actions.hasClass(className.attached)) {
245
+ $actions.addClass(className.extraContent);
246
+ if ($actions.hasClass(className.vertical)) {
247
+ $actions.removeClass(className.vertical);
248
+ module.error(error.verticalCard);
249
+ }
250
+ }
251
+ for (const el of settings.actions) {
252
+ const icon = el[fields.icon]
253
+ ? '<i ' + (el[fields.text] ? 'aria-hidden="true"' : '')
254
+ + ' class="' + module.helpers.escape(el[fields.icon]) + ' icon"></i>'
255
+ : '';
256
+ const text = module.helpers.escape(el[fields.text] || '', settings);
257
+ const cls = module.helpers.escape(el[fields.class] || '');
258
+ const click = el[fields.click] && isFunction(el[fields.click])
259
+ ? el[fields.click]
260
+ : function () {};
261
+ const elementRef = element;
262
+ const $moduleRef = $module;
263
+ $actions.append($('<button/>', {
264
+ html: icon + text,
265
+ 'aria-label': (el[fields.text] || el[fields.icon] || '').replace(/<[^>]+(>|$)/g, ''),
266
+ class: className.button + ' ' + cls,
267
+ on: {
268
+ click: function () {
269
+ const $button = $(this);
270
+ if ($button.is(selector.approve) || $button.is(selector.deny) || click.call(elementRef, $moduleRef) === false) {
271
+ return;
272
+ }
273
+ module.close();
274
+ },
275
+ },
276
+ }));
277
+ }
278
+ }
279
+ if ($actions && $actions.hasClass(className.vertical)) {
280
+ $toast.addClass(className.vertical);
281
+ }
282
+ if ($actions.length > 0 && !$actions.hasClass(className.attached) && $actions && (!$actions.hasClass(className.basic) || $actions.hasClass(className.left))) {
283
+ $toast.addClass(className.actions);
284
+ }
285
+ if (settings.displayTime === 'auto') {
286
+ settings.displayTime = Math.max(settings.minDisplayTime, ($toast.text().split(' ').length / settings.wordsPerMinute) * 60_000);
287
+ }
288
+ $toastBox.append($toast);
289
+
290
+ if ($actions.length > 0 && $actions.hasClass(className.attached)) {
291
+ $actions.addClass(className.buttons);
292
+ $actions.detach();
293
+ $toast.addClass(className.attached);
294
+ if (!$actions.hasClass(className.vertical)) {
295
+ if ($actions.hasClass(className.top)) {
296
+ $toastBox.prepend($actions);
297
+ $toast.addClass(className.bottom);
298
+ } else {
299
+ $toastBox.append($actions);
300
+ $toast.addClass(className.top);
301
+ }
302
+ } else {
303
+ $toast.wrap(
304
+ $('<div/>', {
305
+ class: className.vertical + ' '
306
+ + className.attached + ' '
307
+ + (settings.compact ? className.compact : ''),
308
+ })
309
+ );
310
+ if ($actions.hasClass(className.left)) {
311
+ $toast.addClass(className.left).parent().addClass(className.left).prepend($actions);
312
+ } else {
313
+ $toast.parent().append($actions);
314
+ }
315
+ }
316
+ }
317
+ if ($module !== $toast) {
318
+ $module = $toast;
319
+ element = $toast[0];
320
+ }
321
+ if (settings.displayTime > 0) {
322
+ const progressingClass = className.progressing + ' ' + (settings.pauseOnHover ? className.pausable : '');
323
+ if (settings.showProgress) {
324
+ $progress = $('<div/>', {
325
+ class: className.progress + ' ' + (settings.classProgress || settings.class),
326
+ 'data-percent': '',
327
+ });
328
+ if (!settings.classProgress) {
329
+ if ($toast.hasClass('toast') && !$toast.hasClass(className.inverted)) {
330
+ $progress.addClass(className.inverted);
331
+ } else {
332
+ $progress.removeClass(className.inverted);
333
+ }
334
+ }
335
+ $progressBar = $('<div/>', { class: 'bar ' + (settings.progressUp ? 'up ' : 'down ') + progressingClass });
336
+ $progress
337
+ .addClass(settings.showProgress)
338
+ .append($progressBar);
339
+ if ($progress.hasClass(className.top)) {
340
+ $toastBox.prepend($progress);
341
+ } else {
342
+ $toastBox.append($progress);
343
+ }
344
+ $progressBar.css('animation-duration', settings.displayTime / 1000 + 's');
345
+ }
346
+ $animationObject = $('<span/>', { class: 'wait ' + progressingClass });
347
+ $animationObject.css('animation-duration', settings.displayTime / 1000 + 's');
348
+ $animationObject.appendTo($toast);
349
+ }
350
+ if (settings.compact) {
351
+ $toastBox.addClass(className.compact);
352
+ $toast.addClass(className.compact);
353
+ if ($progress) {
354
+ $progress.addClass(className.compact);
355
+ }
356
+ }
357
+ if (settings.newestOnTop) {
358
+ $toastBox.prependTo(module.get.container());
359
+ } else {
360
+ $toastBox.appendTo(module.get.container());
361
+ }
362
+ },
363
+ },
364
+
365
+ bind: {
366
+ events: function () {
367
+ module.debug('Binding events to toast');
368
+ if (settings.closeIcon) {
369
+ $close.on('click' + eventNamespace, module.event.close);
370
+ }
371
+ $toast.on('click' + eventNamespace, module.event.click);
372
+ if ($animationObject) {
373
+ $animationObject.on('animationend' + eventNamespace, module.event.close);
374
+ }
375
+ $toastBox
376
+ .on('click' + eventNamespace, selector.approve, module.event.approve)
377
+ .on('click' + eventNamespace, selector.deny, module.event.deny);
378
+ },
379
+ },
380
+
381
+ unbind: {
382
+ events: function () {
383
+ module.debug('Unbinding events to toast');
384
+ if (settings.closeIcon) {
385
+ $close.off('click' + eventNamespace);
386
+ }
387
+ $toast.off('click' + eventNamespace);
388
+ if ($animationObject) {
389
+ $animationObject.off('animationend' + eventNamespace);
390
+ }
391
+ $toastBox
392
+ .off('click' + eventNamespace);
393
+ },
394
+ },
395
+
396
+ animate: {
397
+ show: function (callback) {
398
+ callback = isFunction(callback) ? callback : function () {};
399
+ if (settings.transition && module.can.useElement('transition')) {
400
+ module.set.visible();
401
+ $toastBox
402
+ .transition({
403
+ animation: settings.transition.showMethod + ' in',
404
+ queue: false,
405
+ debug: settings.debug,
406
+ verbose: settings.verbose,
407
+ silent: settings.silent,
408
+ duration: settings.transition.showDuration,
409
+ onComplete: function () {
410
+ callback.call($toastBox, element);
411
+ settings.onVisible.call($toastBox, element);
412
+ },
413
+ });
414
+ }
415
+ },
416
+ close: function (callback) {
417
+ callback = isFunction(callback) ? callback : function () {};
418
+ if (settings.transition && $.fn.transition !== undefined) {
419
+ $toastBox
420
+ .transition({
421
+ animation: settings.transition.hideMethod + ' out',
422
+ queue: false,
423
+ duration: settings.transition.hideDuration,
424
+ debug: settings.debug,
425
+ verbose: settings.verbose,
426
+ silent: settings.silent,
427
+ interval: 50,
428
+
429
+ onBeforeHide: function (callback) {
430
+ callback = isFunction(callback) ? callback : function () {};
431
+ if (settings.transition.closeEasing !== '') {
432
+ if ($toastBox) {
433
+ $toastBox.css('opacity', '0');
434
+ $toastBox.wrap('<div/>').parent().hide(settings.transition.closeDuration, settings.transition.closeEasing, function () {
435
+ if ($toastBox) {
436
+ $toastBox.parent().remove();
437
+ callback.call($toastBox);
438
+ }
439
+ });
440
+ }
441
+ } else {
442
+ callback.call($toastBox);
443
+ }
444
+ },
445
+ onComplete: function () {
446
+ callback.call($toastBox, element);
447
+ settings.onHidden.call($toastBox, element);
448
+ module.destroy();
449
+ },
450
+ });
451
+ } else {
452
+ module.error(error.noTransition);
453
+ }
454
+ },
455
+ pause: function () {
456
+ $animationObject.css('animationPlayState', 'paused');
457
+ if ($progressBar) {
458
+ $progressBar.css('animationPlayState', 'paused');
459
+ }
460
+ },
461
+ continue: function () {
462
+ $animationObject.css('animationPlayState', 'running');
463
+ if ($progressBar) {
464
+ $progressBar.css('animationPlayState', 'running');
465
+ }
466
+ },
467
+ },
468
+
469
+ has: {
470
+ container: function () {
471
+ module.verbose('Determining if there is already a container');
472
+
473
+ return module.get.containers().length > 0;
474
+ },
475
+ toast: function () {
476
+ return !!module.get.toast();
477
+ },
478
+ toasts: function () {
479
+ return module.get.toasts().length > 0;
480
+ },
481
+ configActions: function () {
482
+ return Array.isArray(settings.actions) && settings.actions.length > 0;
483
+ },
484
+ },
485
+
486
+ get: {
487
+ id: function () {
488
+ return id;
489
+ },
490
+ containers: function () {
491
+ return $context.children(module.helpers.toClass(settings.position) + selector.container
492
+ + (settings.horizontal
493
+ ? module.helpers.toClass(className.horizontal)
494
+ : ':not(' + module.helpers.toClass(className.horizontal) + ')')
495
+ + (settings.context && settings.context !== 'body'
496
+ ? module.helpers.toClass(className.absolute)
497
+ : ':not(' + module.helpers.toClass(className.absolute) + ')'));
498
+ },
499
+ container: function () {
500
+ return module.get.containers()[0];
501
+ },
502
+ toastBox: function () {
503
+ return $toastBox || null;
504
+ },
505
+ toast: function () {
506
+ return $toast || null;
507
+ },
508
+ toasts: function () {
509
+ return $(module.get.container()).find(selector.box);
510
+ },
511
+ iconClass: function () {
512
+ return typeof settings.showIcon === 'string'
513
+ ? settings.showIcon
514
+ : (settings.showIcon && settings.icons[settings.class]
515
+ ? settings.icons[settings.class]
516
+ : '');
517
+ },
518
+ remainingTime: function () {
519
+ return $animationObject ? $animationObject.css('opacity') * settings.displayTime : 0;
520
+ },
521
+ },
522
+
523
+ set: {
524
+ visible: function () {
525
+ $toast.addClass(className.visible);
526
+ },
527
+ },
528
+
529
+ remove: {
530
+ visible: function () {
531
+ $toast.removeClass(className.visible);
532
+ },
533
+ },
534
+
535
+ event: {
536
+ close: function () {
537
+ module.close();
538
+ },
539
+ click: function (event) {
540
+ if ($(event.target).closest(selector.clickable).length === 0) {
541
+ if (settings.onClick.call($toastBox, element) === false || !settings.closeOnClick) {
542
+ module.verbose('Click callback returned false or close denied by setting cancelling close');
543
+
544
+ return;
545
+ }
546
+ module.close();
547
+ }
548
+ },
549
+ approve: function () {
550
+ if (settings.onApprove.call(element, $module) === false) {
551
+ module.verbose('Approve callback returned false cancelling close');
552
+
553
+ return;
554
+ }
555
+ module.close();
556
+ },
557
+ deny: function () {
558
+ if (settings.onDeny.call(element, $module) === false) {
559
+ module.verbose('Deny callback returned false cancelling close');
560
+
561
+ return;
562
+ }
563
+ module.close();
564
+ },
565
+ },
566
+
567
+ helpers: {
568
+ toClass: function (selector) {
569
+ const classes = selector.trim().split(/\s+/);
570
+ let result = '';
571
+
572
+ for (const element of classes) {
573
+ result += '.' + element;
574
+ }
575
+
576
+ return result;
577
+ },
578
+ escape: function (string, settings) {
579
+ if (settings !== undefined && settings.preserveHTML) {
580
+ return string;
581
+ }
582
+
583
+ const escapeMap = {
584
+ '"': '&quot;',
585
+ '&': '&amp;',
586
+ "'": '&apos;',
587
+ '<': '&lt;',
588
+ '>': '&gt;',
589
+ };
590
+
591
+ return String(string).replace(/["&'<>]/g, (chr) => escapeMap[chr]);
592
+ },
593
+ },
594
+
595
+ can: {
596
+ useElement: function (element) {
597
+ if ($.fn[element] !== undefined) {
598
+ return true;
599
+ }
600
+ module.error(error.noElement.replace('{element}', element));
601
+
602
+ return false;
603
+ },
604
+ },
605
+
606
+ setting: function (name, value) {
607
+ module.debug('Changing setting', name, value);
608
+ if ($.isPlainObject(name)) {
609
+ $.extend(true, settings, name);
610
+ } else if (value !== undefined) {
611
+ if ($.isPlainObject(settings[name])) {
612
+ $.extend(true, settings[name], value);
613
+ } else {
614
+ settings[name] = value;
615
+ }
616
+ } else {
617
+ return settings[name];
618
+ }
619
+ },
620
+ internal: function (name, value) {
621
+ if ($.isPlainObject(name)) {
622
+ $.extend(true, module, name);
623
+ } else if (value !== undefined) {
624
+ module[name] = value;
625
+ } else {
626
+ return module[name];
627
+ }
628
+ },
629
+ debug: function (...args) {
630
+ if (!settings.silent && settings.debug) {
631
+ if (settings.performance) {
632
+ module.performance.log(args);
633
+ } else {
634
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
635
+ module.debug.apply(console, args);
636
+ }
637
+ }
638
+ },
639
+ verbose: function (...args) {
640
+ if (!settings.silent && settings.verbose && settings.debug) {
641
+ if (settings.performance) {
642
+ module.performance.log(args);
643
+ } else {
644
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
645
+ module.verbose.apply(console, args);
646
+ }
647
+ }
648
+ },
649
+ error: function (...args) {
650
+ if (!settings.silent) {
651
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
652
+ module.error.apply(console, args);
653
+ }
654
+ },
655
+ performance: {
656
+ log: function (message) {
657
+ let currentTime;
658
+ let executionTime;
659
+ let previousTime;
660
+ if (settings.performance) {
661
+ currentTime = Date.now();
662
+ previousTime = time || currentTime;
663
+ executionTime = currentTime - previousTime;
664
+ time = currentTime;
665
+ performance.push({
666
+ Name: message[0],
667
+ Arguments: message.slice(1),
668
+ Element: element,
669
+ 'Execution Time': executionTime,
670
+ });
671
+ }
672
+ clearTimeout(module.performance.timer);
673
+ module.performance.timer = setTimeout(function () {
674
+ module.performance.display();
675
+ }, 500);
676
+ },
677
+ display: function () {
678
+ let title = settings.name + ':';
679
+ let totalTime = 0;
680
+ time = false;
681
+ clearTimeout(module.performance.timer);
682
+ $.each(performance, function (index, data) {
683
+ totalTime += data['Execution Time'];
684
+ });
685
+ title += ' ' + totalTime + 'ms';
686
+ if (performance.length > 0) {
687
+ console.groupCollapsed(title);
688
+ console.table(performance);
689
+ console.groupEnd();
690
+ }
691
+ performance = [];
692
+ },
693
+ },
694
+ invoke: function (query, passedArguments = queryArguments, context = element) {
695
+ let object = instance;
696
+ let maxDepth;
697
+ let found;
698
+ let response;
699
+ if (typeof query === 'string' && object !== undefined) {
700
+ query = query.split(/[ .]/);
701
+ maxDepth = query.length - 1;
702
+ $.each(query, function (depth, value) {
703
+ const camelCaseValue = depth !== maxDepth
704
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
705
+ : query;
706
+ if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
707
+ object = object[camelCaseValue];
708
+ } else if (object[camelCaseValue] !== undefined) {
709
+ found = object[camelCaseValue];
710
+
711
+ return false;
712
+ } else if ($.isPlainObject(object[value]) && (depth !== maxDepth)) {
713
+ object = object[value];
714
+ } else if (object[value] !== undefined) {
715
+ found = object[value];
716
+
717
+ return false;
718
+ } else {
719
+ module.error(error.method, query);
720
+
721
+ return false;
722
+ }
723
+ });
724
+ }
725
+ if (isFunction(found)) {
726
+ response = found.apply(context, passedArguments);
727
+ } else if (found !== undefined) {
728
+ response = found;
729
+ }
730
+ if (Array.isArray(returnedValue)) {
731
+ returnedValue.push(response);
732
+ } else if (returnedValue !== undefined) {
733
+ returnedValue = [returnedValue, response];
734
+ } else if (response !== undefined) {
735
+ returnedValue = response;
736
+ }
737
+
738
+ return found;
739
+ },
740
+ };
741
+
742
+ if (methodInvoked) {
743
+ if (instance === undefined) {
744
+ module.initialize();
745
+ }
746
+ module.invoke(parameters);
747
+ } else {
748
+ if (instance !== undefined) {
749
+ instance.invoke('destroy');
750
+ }
751
+ module.initialize();
752
+ returnedValue = $module;
753
+ }
754
+ });
755
+
756
+ return returnedValue !== undefined
757
+ ? returnedValue
758
+ : this;
759
+ };
760
+ $.toast = $.fn.toast;
761
+
762
+ $.fn.toast.settings = {
763
+
764
+ name: 'Toast',
765
+ namespace: 'toast',
766
+
767
+ silent: false,
768
+ debug: false,
769
+ verbose: false,
770
+ performance: true,
771
+
772
+ context: 'body',
773
+
774
+ position: 'top right',
775
+ horizontal: false,
776
+ class: 'neutral',
777
+ classProgress: false,
778
+ classActions: false,
779
+ classImage: 'mini',
780
+
781
+ title: '',
782
+ message: '',
783
+ displayTime: 3000, // set to zero to require manual dismissal, otherwise hides on its own
784
+ minDisplayTime: 1000, // minimum display time in case displayTime is set to 'auto'
785
+ wordsPerMinute: 120,
786
+ showIcon: false,
787
+ newestOnTop: false,
788
+ showProgress: false,
789
+ pauseOnHover: true,
790
+ progressUp: false, // if true, the bar will start at 0% and increase to 100%
791
+ opacity: 1,
792
+ compact: true,
793
+ closeIcon: false,
794
+ closeOnClick: true,
795
+ cloneModule: true,
796
+ actions: false,
797
+ preserveHTML: false,
798
+ showImage: false,
799
+ alt: false,
800
+
801
+ // transition settings
802
+ transition: {
803
+ showMethod: 'scale',
804
+ showDuration: 500,
805
+ hideMethod: 'scale',
806
+ hideDuration: 500,
807
+ closeEasing: 'easeOutCubic', // Set to empty string to stack the closed toast area immediately (old behavior)
808
+ closeDuration: 500,
809
+ },
810
+
811
+ error: {
812
+ method: 'The method you called is not defined.',
813
+ noElement: 'This module requires ui {element}',
814
+ verticalCard: 'Vertical but not attached actions are not supported for card layout',
815
+ },
816
+
817
+ className: {
818
+ container: 'ui toast-container',
819
+ absolute: 'absolute',
820
+ box: 'floating toast-box',
821
+ progress: 'ui attached active progress',
822
+ toast: 'ui toast',
823
+ icon: 'centered icon',
824
+ visible: 'visible',
825
+ content: 'content',
826
+ title: 'ui header',
827
+ message: 'message',
828
+ actions: 'actions',
829
+ extraContent: 'extra content',
830
+ button: 'ui button',
831
+ buttons: 'ui buttons',
832
+ close: 'close icon',
833
+ image: 'ui image',
834
+ vertical: 'vertical',
835
+ horizontal: 'horizontal',
836
+ attached: 'attached',
837
+ inverted: 'inverted',
838
+ compact: 'compact',
839
+ pausable: 'pausable',
840
+ progressing: 'progressing',
841
+ top: 'top',
842
+ bottom: 'bottom',
843
+ left: 'left',
844
+ basic: 'basic',
845
+ unclickable: 'unclickable',
846
+ },
847
+
848
+ text: {
849
+ close: 'Close',
850
+ },
851
+
852
+ icons: {
853
+ info: 'info',
854
+ success: 'checkmark',
855
+ warning: 'warning',
856
+ error: 'times',
857
+ },
858
+
859
+ selector: {
860
+ container: '.ui.toast-container',
861
+ box: '.toast-box',
862
+ toast: '.ui.toast',
863
+ title: '.header',
864
+ message: '.message:not(.ui)',
865
+ image: '> img.image, > .image > img',
866
+ icon: '> i.icon',
867
+ input: 'input:not([type="hidden"]), textarea, select, button, .ui.button, ui.dropdown',
868
+ clickable: 'a, details, .ui.accordion',
869
+ approve: '.actions .positive, .actions .approve, .actions .ok',
870
+ deny: '.actions .negative, .actions .deny, .actions .cancel',
871
+ },
872
+
873
+ fields: {
874
+ class: 'class',
875
+ text: 'text',
876
+ icon: 'icon',
877
+ click: 'click',
878
+ },
879
+
880
+ // callbacks
881
+ onShow: function () {},
882
+ onVisible: function () {},
883
+ onClick: function () {},
884
+ onHide: function () {},
885
+ onHidden: function () {},
886
+ onRemove: function () {},
887
+ onApprove: function () {},
888
+ onDeny: function () {},
889
+ };
890
+
891
+ $.extend($.easing, {
892
+ easeOutBounce: function (x) {
893
+ const n1 = 7.5625;
894
+ const d1 = 2.75;
895
+ if (x < 1 / d1) {
896
+ return n1 * x * x;
897
+ }
898
+ if (x < 2 / d1) {
899
+ x -= 1.5 / d1;
900
+
901
+ return n1 * x * x + 0.75;
902
+ }
903
+ if (x < 2.5 / d1) {
904
+ x -= 2.25 / d1;
905
+
906
+ return n1 * x * x + 0.9375;
907
+ }
908
+ x -= 2.625 / d1;
909
+
910
+ return n1 * x * x + 0.984_375;
911
+ },
912
+ easeOutCubic: function (t) {
913
+ return --t * t * t + 1;
914
+ },
915
+ });
916
+ })(jQuery, window, document);