rails-active-ui 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/datatables.css +15 -0
  3. data/app/assets/stylesheets.css +5 -1
  4. data/app/blocks/resource_list_block.rb +153 -0
  5. data/app/components/back_button_component.rb +34 -0
  6. data/app/components/button_component.rb +4 -2
  7. data/app/components/button_to_component.rb +3 -4
  8. data/app/components/column_component.rb +1 -1
  9. data/app/components/container_component.rb +1 -1
  10. data/app/components/dropdown_component.rb +8 -2
  11. data/app/components/grid_component.rb +5 -1
  12. data/app/components/link_to_component.rb +23 -0
  13. data/app/components/menu_item_component.rb +5 -1
  14. data/app/components/message_component.rb +3 -1
  15. data/app/components/modal_component.rb +23 -3
  16. data/app/components/paragraph_component.rb +13 -0
  17. data/app/components/row_component.rb +1 -1
  18. data/app/components/table_row_component.rb +3 -5
  19. data/app/components/template_component.rb +13 -0
  20. data/app/helpers/component_helper.rb +122 -76
  21. data/app/helpers/fui_helper.rb +37 -0
  22. data/app/javascript/datatables.js +10 -0
  23. data/app/javascript/ui/controllers/fui_datatable_controller.js +35 -0
  24. data/app/javascript/ui/controllers/fui_dropdown_controller.js +8 -1
  25. data/app/javascript/ui/controllers/fui_item_list_controller.js +40 -0
  26. data/app/javascript/ui/controllers/navigation_controller.js +23 -0
  27. data/app/javascript/ui/index.js +11 -0
  28. data/app/lib/component.rb +1 -1
  29. data/config/importmap.rb +3 -0
  30. data/config/initializers/ruby_template_handler.rb +4 -1
  31. data/formantic-ui/components/accordion.css +369 -0
  32. data/formantic-ui/components/accordion.js +595 -0
  33. data/formantic-ui/components/accordion.min.css +9 -0
  34. data/formantic-ui/components/accordion.min.js +11 -0
  35. data/formantic-ui/components/ad.css +264 -0
  36. data/formantic-ui/components/ad.min.css +10 -0
  37. data/formantic-ui/components/api.js +1225 -0
  38. data/formantic-ui/components/api.min.js +11 -0
  39. data/formantic-ui/components/breadcrumb.css +135 -0
  40. data/formantic-ui/components/breadcrumb.min.css +9 -0
  41. data/formantic-ui/components/button.css +4058 -0
  42. data/formantic-ui/components/button.min.css +9 -0
  43. data/formantic-ui/components/calendar.css +327 -0
  44. data/formantic-ui/components/calendar.js +2045 -0
  45. data/formantic-ui/components/calendar.min.css +9 -0
  46. data/formantic-ui/components/calendar.min.js +11 -0
  47. data/formantic-ui/components/card.css +1881 -0
  48. data/formantic-ui/components/card.min.css +9 -0
  49. data/formantic-ui/components/checkbox.css +785 -0
  50. data/formantic-ui/components/checkbox.js +888 -0
  51. data/formantic-ui/components/checkbox.min.css +9 -0
  52. data/formantic-ui/components/checkbox.min.js +11 -0
  53. data/formantic-ui/components/comment.css +283 -0
  54. data/formantic-ui/components/comment.min.css +9 -0
  55. data/formantic-ui/components/container.css +300 -0
  56. data/formantic-ui/components/container.min.css +9 -0
  57. data/formantic-ui/components/dimmer.css +367 -0
  58. data/formantic-ui/components/dimmer.js +732 -0
  59. data/formantic-ui/components/dimmer.min.css +9 -0
  60. data/formantic-ui/components/dimmer.min.js +11 -0
  61. data/formantic-ui/components/divider.css +287 -0
  62. data/formantic-ui/components/divider.min.css +9 -0
  63. data/formantic-ui/components/dropdown.css +2087 -0
  64. data/formantic-ui/components/dropdown.js +4432 -0
  65. data/formantic-ui/components/dropdown.min.css +9 -0
  66. data/formantic-ui/components/dropdown.min.js +11 -0
  67. data/formantic-ui/components/embed.css +155 -0
  68. data/formantic-ui/components/embed.js +688 -0
  69. data/formantic-ui/components/embed.min.css +9 -0
  70. data/formantic-ui/components/embed.min.js +11 -0
  71. data/formantic-ui/components/emoji.css +15311 -0
  72. data/formantic-ui/components/emoji.min.css +9 -0
  73. data/formantic-ui/components/feed.css +799 -0
  74. data/formantic-ui/components/feed.min.css +9 -0
  75. data/formantic-ui/components/flag.css +1149 -0
  76. data/formantic-ui/components/flag.min.css +9 -0
  77. data/formantic-ui/components/flyout.css +546 -0
  78. data/formantic-ui/components/flyout.js +1551 -0
  79. data/formantic-ui/components/flyout.min.css +9 -0
  80. data/formantic-ui/components/flyout.min.js +11 -0
  81. data/formantic-ui/components/form.css +1885 -0
  82. data/formantic-ui/components/form.js +2199 -0
  83. data/formantic-ui/components/form.min.css +9 -0
  84. data/formantic-ui/components/form.min.js +11 -0
  85. data/formantic-ui/components/grid.css +1952 -0
  86. data/formantic-ui/components/grid.min.css +9 -0
  87. data/formantic-ui/components/header.css +778 -0
  88. data/formantic-ui/components/header.min.css +9 -0
  89. data/formantic-ui/components/icon.css +7066 -0
  90. data/formantic-ui/components/icon.min.css +9 -0
  91. data/formantic-ui/components/image.css +315 -0
  92. data/formantic-ui/components/image.min.css +9 -0
  93. data/formantic-ui/components/input.css +1566 -0
  94. data/formantic-ui/components/input.min.css +9 -0
  95. data/formantic-ui/components/item.css +534 -0
  96. data/formantic-ui/components/item.min.css +9 -0
  97. data/formantic-ui/components/label.css +2114 -0
  98. data/formantic-ui/components/label.min.css +9 -0
  99. data/formantic-ui/components/list.css +955 -0
  100. data/formantic-ui/components/list.min.css +9 -0
  101. data/formantic-ui/components/loader.css +787 -0
  102. data/formantic-ui/components/loader.min.css +9 -0
  103. data/formantic-ui/components/menu.css +2131 -0
  104. data/formantic-ui/components/menu.min.css +9 -0
  105. data/formantic-ui/components/message.css +619 -0
  106. data/formantic-ui/components/message.min.css +9 -0
  107. data/formantic-ui/components/modal.css +779 -0
  108. data/formantic-ui/components/modal.js +1637 -0
  109. data/formantic-ui/components/modal.min.css +9 -0
  110. data/formantic-ui/components/modal.min.js +11 -0
  111. data/formantic-ui/components/nag.css +290 -0
  112. data/formantic-ui/components/nag.js +566 -0
  113. data/formantic-ui/components/nag.min.css +9 -0
  114. data/formantic-ui/components/nag.min.js +11 -0
  115. data/formantic-ui/components/placeholder.css +228 -0
  116. data/formantic-ui/components/placeholder.min.css +9 -0
  117. data/formantic-ui/components/popup.css +1184 -0
  118. data/formantic-ui/components/popup.js +1561 -0
  119. data/formantic-ui/components/popup.min.css +9 -0
  120. data/formantic-ui/components/popup.min.js +11 -0
  121. data/formantic-ui/components/progress.css +761 -0
  122. data/formantic-ui/components/progress.js +979 -0
  123. data/formantic-ui/components/progress.min.css +9 -0
  124. data/formantic-ui/components/progress.min.js +11 -0
  125. data/formantic-ui/components/rail.css +147 -0
  126. data/formantic-ui/components/rail.min.css +9 -0
  127. data/formantic-ui/components/rating.css +414 -0
  128. data/formantic-ui/components/rating.js +540 -0
  129. data/formantic-ui/components/rating.min.css +9 -0
  130. data/formantic-ui/components/rating.min.js +11 -0
  131. data/formantic-ui/components/reset.css +386 -0
  132. data/formantic-ui/components/reset.min.css +9 -0
  133. data/formantic-ui/components/reveal.css +277 -0
  134. data/formantic-ui/components/reveal.min.css +9 -0
  135. data/formantic-ui/components/search.css +541 -0
  136. data/formantic-ui/components/search.js +1641 -0
  137. data/formantic-ui/components/search.min.css +9 -0
  138. data/formantic-ui/components/search.min.js +11 -0
  139. data/formantic-ui/components/segment.css +1053 -0
  140. data/formantic-ui/components/segment.min.css +9 -0
  141. data/formantic-ui/components/shape.css +144 -0
  142. data/formantic-ui/components/shape.js +797 -0
  143. data/formantic-ui/components/shape.min.css +9 -0
  144. data/formantic-ui/components/shape.min.js +11 -0
  145. data/formantic-ui/components/sidebar.css +539 -0
  146. data/formantic-ui/components/sidebar.js +1054 -0
  147. data/formantic-ui/components/sidebar.min.css +9 -0
  148. data/formantic-ui/components/sidebar.min.js +11 -0
  149. data/formantic-ui/components/site.css +286 -0
  150. data/formantic-ui/components/site.js +455 -0
  151. data/formantic-ui/components/site.min.css +9 -0
  152. data/formantic-ui/components/site.min.js +11 -0
  153. data/formantic-ui/components/slider.css +926 -0
  154. data/formantic-ui/components/slider.js +1546 -0
  155. data/formantic-ui/components/slider.min.css +9 -0
  156. data/formantic-ui/components/slider.min.js +11 -0
  157. data/formantic-ui/components/state.js +697 -0
  158. data/formantic-ui/components/state.min.js +11 -0
  159. data/formantic-ui/components/statistic.css +586 -0
  160. data/formantic-ui/components/statistic.min.css +9 -0
  161. data/formantic-ui/components/step.css +1538 -0
  162. data/formantic-ui/components/step.min.css +9 -0
  163. data/formantic-ui/components/sticky.css +73 -0
  164. data/formantic-ui/components/sticky.js +917 -0
  165. data/formantic-ui/components/sticky.min.css +9 -0
  166. data/formantic-ui/components/sticky.min.js +11 -0
  167. data/formantic-ui/components/tab.css +84 -0
  168. data/formantic-ui/components/tab.js +967 -0
  169. data/formantic-ui/components/tab.min.css +9 -0
  170. data/formantic-ui/components/tab.min.js +11 -0
  171. data/formantic-ui/components/table.css +3473 -0
  172. data/formantic-ui/components/table.min.css +9 -0
  173. data/formantic-ui/components/text.css +155 -0
  174. data/formantic-ui/components/text.min.css +9 -0
  175. data/formantic-ui/components/toast.css +751 -0
  176. data/formantic-ui/components/toast.js +964 -0
  177. data/formantic-ui/components/toast.min.css +9 -0
  178. data/formantic-ui/components/toast.min.js +11 -0
  179. data/formantic-ui/components/transition.css +1148 -0
  180. data/formantic-ui/components/transition.js +1034 -0
  181. data/formantic-ui/components/transition.min.css +9 -0
  182. data/formantic-ui/components/transition.min.js +11 -0
  183. data/formantic-ui/components/visibility.js +1292 -0
  184. data/formantic-ui/components/visibility.min.js +11 -0
  185. data/formantic-ui/semantic.css +78485 -0
  186. data/formantic-ui/semantic.js +31036 -0
  187. data/formantic-ui/semantic.min.css +11 -0
  188. data/formantic-ui/semantic.min.js +11 -0
  189. data/formantic-ui/themes/basic/assets/fonts/LICENSE.txt +91 -0
  190. data/formantic-ui/themes/basic/assets/fonts/icons.woff +0 -0
  191. data/formantic-ui/themes/basic/assets/fonts/icons.woff2 +0 -0
  192. data/formantic-ui/themes/default/assets/fonts/LICENSE_Lato.txt +94 -0
  193. data/formantic-ui/themes/default/assets/fonts/LICENSE_icons.txt +165 -0
  194. data/formantic-ui/themes/default/assets/fonts/Lato-Bold.woff +0 -0
  195. data/formantic-ui/themes/default/assets/fonts/Lato-Bold.woff2 +0 -0
  196. data/formantic-ui/themes/default/assets/fonts/Lato-BoldItalic.woff +0 -0
  197. data/formantic-ui/themes/default/assets/fonts/Lato-BoldItalic.woff2 +0 -0
  198. data/formantic-ui/themes/default/assets/fonts/Lato-Italic.woff +0 -0
  199. data/formantic-ui/themes/default/assets/fonts/Lato-Italic.woff2 +0 -0
  200. data/formantic-ui/themes/default/assets/fonts/Lato-Regular.woff +0 -0
  201. data/formantic-ui/themes/default/assets/fonts/Lato-Regular.woff2 +0 -0
  202. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Bold.woff +0 -0
  203. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Bold.woff2 +0 -0
  204. data/formantic-ui/themes/default/assets/fonts/LatoLatin-BoldItalic.woff +0 -0
  205. data/formantic-ui/themes/default/assets/fonts/LatoLatin-BoldItalic.woff2 +0 -0
  206. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Italic.woff +0 -0
  207. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Italic.woff2 +0 -0
  208. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Regular.woff +0 -0
  209. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Regular.woff2 +0 -0
  210. data/formantic-ui/themes/default/assets/fonts/brand-icons.woff +0 -0
  211. data/formantic-ui/themes/default/assets/fonts/brand-icons.woff2 +0 -0
  212. data/formantic-ui/themes/default/assets/fonts/icons.woff +0 -0
  213. data/formantic-ui/themes/default/assets/fonts/icons.woff2 +0 -0
  214. data/formantic-ui/themes/default/assets/fonts/outline-icons.woff +0 -0
  215. data/formantic-ui/themes/default/assets/fonts/outline-icons.woff2 +0 -0
  216. data/formantic-ui/themes/famfamfam/assets/images/flags.png +0 -0
  217. data/formantic-ui/themes/github/assets/fonts/LICENSE.txt +94 -0
  218. data/formantic-ui/themes/github/assets/fonts/octicons.woff +0 -0
  219. data/formantic-ui/themes/github/assets/fonts/octicons.woff2 +0 -0
  220. data/formantic-ui/themes/material/assets/fonts/LICENSE.txt +202 -0
  221. data/formantic-ui/themes/material/assets/fonts/icons.woff +0 -0
  222. data/formantic-ui/themes/material/assets/fonts/icons.woff2 +0 -0
  223. data/lib/ui/engine.rb +7 -2
  224. data/lib/ui/version.rb +1 -1
  225. metadata +205 -7
  226. data/app/components/link_component.rb +0 -23
@@ -0,0 +1,979 @@
1
+ /*!
2
+ * # Fomantic-UI 2.9.4 - Progress
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.progress = function (parameters) {
23
+ var
24
+ $allModules = $(this),
25
+
26
+ time = Date.now(),
27
+ performance = [],
28
+
29
+ query = arguments[0],
30
+ methodInvoked = typeof query === 'string',
31
+ queryArguments = [].slice.call(arguments, 1),
32
+
33
+ returnedValue
34
+ ;
35
+
36
+ $allModules.each(function () {
37
+ var
38
+ settings = $.isPlainObject(parameters)
39
+ ? $.extend(true, {}, $.fn.progress.settings, parameters)
40
+ : $.extend({}, $.fn.progress.settings),
41
+
42
+ className = settings.className,
43
+ metadata = settings.metadata,
44
+ namespace = settings.namespace,
45
+ selector = settings.selector,
46
+ error = settings.error,
47
+
48
+ eventNamespace = '.' + namespace,
49
+ moduleNamespace = 'module-' + namespace,
50
+
51
+ $module = $(this),
52
+ $bars = $(this).find(selector.bar),
53
+ $progresses = $(this).find(selector.progress),
54
+ $label = $(this).find(selector.label),
55
+
56
+ element = this,
57
+ instance = $module.data(moduleNamespace),
58
+
59
+ animating = false,
60
+ module
61
+ ;
62
+ module = {
63
+ helper: {
64
+ sum: function (nums) {
65
+ return Array.isArray(nums) ? nums.reduce(function (left, right) {
66
+ return left + Number(right);
67
+ }, 0) : 0;
68
+ },
69
+ /**
70
+ * Derive precision for multiple progress with total and values.
71
+ *
72
+ * This helper dervices a precision that is sufficiently large to show minimum value of multiple progress.
73
+ *
74
+ * Example1
75
+ * - total: 1122
76
+ * - values: [325, 111, 74, 612]
77
+ * - min ratio: 74/1122 = 0.0659...
78
+ * - required precision: 100
79
+ *
80
+ * Example2
81
+ * - total: 10541
82
+ * - values: [3235, 1111, 74, 6121]
83
+ * - min ratio: 74/10541 = 0.0070...
84
+ * - required precision: 1000
85
+ *
86
+ * @param min A minimum value within multiple values
87
+ * @param total A total amount of multiple values
88
+ * @returns {number} A precision. Could be 1, 10, 100, ... 1e+10.
89
+ */
90
+ derivePrecision: function (min, total) {
91
+ var precisionPower = 0;
92
+ var precision = 1;
93
+ var ratio = min / total;
94
+ while (precisionPower < 10) {
95
+ ratio *= precision;
96
+ if (ratio > 1) {
97
+ break;
98
+ }
99
+ precision = Math.pow(10, precisionPower++);
100
+ }
101
+
102
+ return precision;
103
+ },
104
+ forceArray: function (element) {
105
+ return Array.isArray(element)
106
+ ? element
107
+ : (!isNaN(element)
108
+ ? [element]
109
+ : (typeof element === 'string' ? element.split(',') : [])); // eslint-disable-line unicorn/no-nested-ternary
110
+ },
111
+ },
112
+
113
+ initialize: function () {
114
+ module.set.duration();
115
+ module.debug(element);
116
+
117
+ module.read.metadata();
118
+ module.read.settings();
119
+
120
+ module.instantiate();
121
+ },
122
+
123
+ instantiate: function () {
124
+ module.verbose('Storing instance of progress', module);
125
+ instance = module;
126
+ $module
127
+ .data(moduleNamespace, module)
128
+ ;
129
+ },
130
+ destroy: function () {
131
+ module.verbose('Destroying previous progress for', $module);
132
+ clearInterval(instance.interval);
133
+ module.remove.state();
134
+ $module.removeData(moduleNamespace);
135
+ instance = undefined;
136
+ },
137
+
138
+ reset: function () {
139
+ module.remove.nextValue();
140
+ module.update.progress(0);
141
+ },
142
+
143
+ complete: function (keepState) {
144
+ if (module.percent === undefined || module.percent < 100) {
145
+ module.remove.progressPoll();
146
+ if (keepState !== true) {
147
+ module.set.percent(100);
148
+ }
149
+ }
150
+ },
151
+
152
+ read: {
153
+ metadata: function () {
154
+ var
155
+ data = {
156
+ percent: module.helper.forceArray($module.data(metadata.percent)),
157
+ total: $module.data(metadata.total),
158
+ value: module.helper.forceArray($module.data(metadata.value)),
159
+ }
160
+ ;
161
+ if (data.total !== undefined) {
162
+ module.debug('Total value set from metadata', data.total);
163
+ module.set.total(data.total);
164
+ }
165
+ if (data.value.length > 0) {
166
+ module.debug('Current value set from metadata', data.value);
167
+ module.set.value(data.value);
168
+ module.set.progress(data.value);
169
+ }
170
+ if (data.percent.length > 0) {
171
+ module.debug('Current percent value set from metadata', data.percent);
172
+ module.set.percent(data.percent);
173
+ }
174
+ },
175
+ settings: function () {
176
+ if (settings.total !== false) {
177
+ module.debug('Current total set in settings', settings.total);
178
+ module.set.total(settings.total);
179
+ }
180
+ if (settings.value !== false) {
181
+ module.debug('Current value set in settings', settings.value);
182
+ module.set.value(settings.value);
183
+ module.set.progress(module.value);
184
+ }
185
+ if (settings.percent !== false) {
186
+ module.debug('Current percent set in settings', settings.percent);
187
+ module.set.percent(settings.percent);
188
+ }
189
+ },
190
+ },
191
+
192
+ bind: {
193
+ transitionEnd: function (callback) {
194
+ $bars
195
+ .one('transitionend' + eventNamespace, function (event) {
196
+ clearTimeout(module.failSafeTimer);
197
+ callback.call(this, event);
198
+ })
199
+ ;
200
+ module.failSafeTimer = setTimeout(function () {
201
+ $bars.triggerHandler('transitionend');
202
+ }, settings.duration + settings.failSafeDelay);
203
+ module.verbose('Adding fail safe timer', module.timer);
204
+ },
205
+ },
206
+
207
+ increment: function (incrementValue) {
208
+ var
209
+ startValue,
210
+ newValue
211
+ ;
212
+ if (module.has.total()) {
213
+ startValue = module.get.value();
214
+ incrementValue = incrementValue || 1;
215
+ } else {
216
+ startValue = module.get.percent();
217
+ incrementValue = incrementValue || module.get.randomValue();
218
+ }
219
+ newValue = startValue + incrementValue;
220
+ module.debug('Incrementing percentage by', startValue, newValue, incrementValue);
221
+ newValue = module.get.normalizedValue(newValue);
222
+ module.set.progress(newValue);
223
+ },
224
+ decrement: function (decrementValue) {
225
+ var
226
+ total = module.get.total(),
227
+ startValue,
228
+ newValue
229
+ ;
230
+ if (total) {
231
+ startValue = module.get.value();
232
+ decrementValue = decrementValue || 1;
233
+ newValue = startValue - decrementValue;
234
+ module.debug('Decrementing value by', decrementValue, startValue);
235
+ } else {
236
+ startValue = module.get.percent();
237
+ decrementValue = decrementValue || module.get.randomValue();
238
+ newValue = startValue - decrementValue;
239
+ module.debug('Decrementing percentage by', decrementValue, startValue);
240
+ }
241
+ newValue = module.get.normalizedValue(newValue);
242
+ module.set.progress(newValue);
243
+ },
244
+
245
+ has: {
246
+ progressPoll: function () {
247
+ return module.progressPoll;
248
+ },
249
+ total: function () {
250
+ return module.get.total() !== false;
251
+ },
252
+ },
253
+
254
+ get: {
255
+ text: function (templateText, index) {
256
+ if (!index) {
257
+ index = 0;
258
+ }
259
+
260
+ var
261
+ value = module.get.value(index),
262
+ total = module.get.total(),
263
+ percent = animating
264
+ ? module.get.displayPercent(index)
265
+ : module.get.percent(index),
266
+ left = total !== false
267
+ ? Math.max(0, total - value)
268
+ : 100 - percent
269
+ ;
270
+ templateText = templateText || '';
271
+ templateText = templateText
272
+ .replace('{value}', value)
273
+ .replace('{total}', total || 0)
274
+ .replace('{left}', left)
275
+ .replace('{percent}', percent)
276
+ .replace('{bar}', settings.text.bars[index] || '')
277
+ ;
278
+ module.verbose('Adding variables to progress bar text', templateText);
279
+
280
+ return templateText;
281
+ },
282
+
283
+ normalizedValue: function (value) {
284
+ if (value < 0) {
285
+ module.debug('Value cannot decrement below 0');
286
+
287
+ return 0;
288
+ }
289
+ if (module.has.total()) {
290
+ if (value > module.total) {
291
+ module.debug('Value cannot increment above total', module.total);
292
+
293
+ return module.total;
294
+ }
295
+ } else if (value > 100) {
296
+ module.debug('Value cannot increment above 100 percent');
297
+
298
+ return 100;
299
+ }
300
+
301
+ return value;
302
+ },
303
+
304
+ updateInterval: function () {
305
+ if (settings.updateInterval === 'auto') {
306
+ return settings.duration;
307
+ }
308
+
309
+ return settings.updateInterval;
310
+ },
311
+
312
+ randomValue: function () {
313
+ module.debug('Generating random increment percentage');
314
+
315
+ return Math.floor((Math.random() * settings.random.max) + settings.random.min);
316
+ },
317
+
318
+ numericValue: function (value) {
319
+ return typeof value === 'string'
320
+ ? (value.replace(/[^\d.]/g, '') !== ''
321
+ ? +value.replace(/[^\d.]/g, '')
322
+ : false)
323
+ : value;
324
+ },
325
+
326
+ // gets current displayed percentage (if animating values this is the intermediary value)
327
+ displayPercent: function (index) {
328
+ var
329
+ $bar = $($bars[index]),
330
+ barWidth = $bar.width(),
331
+ totalWidth = $module.width(),
332
+ minDisplay = parseInt($bar.css('min-width'), 10),
333
+ displayPercent = barWidth > minDisplay
334
+ ? (barWidth / totalWidth) * 100
335
+ : module.percent
336
+ ;
337
+
338
+ return settings.precision > 0
339
+ ? Math.round(displayPercent * (10 * settings.precision)) / (10 * settings.precision)
340
+ : Math.round(displayPercent);
341
+ },
342
+
343
+ percent: function (index) {
344
+ return (module.percent && module.percent[index || 0]) || 0;
345
+ },
346
+ value: function (index) {
347
+ return module.nextValue || (module.value && module.value[index || 0]) || 0;
348
+ },
349
+ total: function () {
350
+ return module.total !== undefined ? module.total : false;
351
+ },
352
+ },
353
+
354
+ create: {
355
+ progressPoll: function () {
356
+ module.progressPoll = setTimeout(function () {
357
+ module.update.toNextValue();
358
+ module.remove.progressPoll();
359
+ }, module.get.updateInterval());
360
+ },
361
+ },
362
+
363
+ is: {
364
+ complete: function () {
365
+ return module.is.success() || module.is.warning() || module.is.error();
366
+ },
367
+ success: function () {
368
+ return $module.hasClass(className.success);
369
+ },
370
+ warning: function () {
371
+ return $module.hasClass(className.warning);
372
+ },
373
+ error: function () {
374
+ return $module.hasClass(className.error);
375
+ },
376
+ active: function () {
377
+ return $module.hasClass(className.active);
378
+ },
379
+ visible: function () {
380
+ return $module.is(':visible');
381
+ },
382
+ },
383
+
384
+ remove: {
385
+ progressPoll: function () {
386
+ module.verbose('Removing progress poll timer');
387
+ if (module.progressPoll) {
388
+ clearTimeout(module.progressPoll);
389
+ delete module.progressPoll;
390
+ }
391
+ },
392
+ nextValue: function () {
393
+ module.verbose('Removing progress value stored for next update');
394
+ delete module.nextValue;
395
+ },
396
+ state: function () {
397
+ module.verbose('Removing stored state');
398
+ delete module.total;
399
+ delete module.percent;
400
+ delete module.value;
401
+ },
402
+ active: function () {
403
+ module.verbose('Removing active state');
404
+ $module.removeClass(className.active);
405
+ },
406
+ success: function () {
407
+ module.verbose('Removing success state');
408
+ $module.removeClass(className.success);
409
+ },
410
+ warning: function () {
411
+ module.verbose('Removing warning state');
412
+ $module.removeClass(className.warning);
413
+ },
414
+ error: function () {
415
+ module.verbose('Removing error state');
416
+ $module.removeClass(className.error);
417
+ },
418
+ },
419
+
420
+ set: {
421
+ barWidth: function (values) {
422
+ module.debug('set bar width with ', values);
423
+ values = module.helper.forceArray(values);
424
+ var firstNonZeroIndex = -1;
425
+ var lastNonZeroIndex = -1;
426
+ var valuesSum = module.helper.sum(values);
427
+ var barCounts = $bars.length;
428
+ var isMultiple = barCounts > 1;
429
+ var percents = values.map(function (value, index) {
430
+ var allZero = index === barCounts - 1 && valuesSum === 0;
431
+ var $bar = $($bars[index]);
432
+ if (value === 0 && isMultiple && !allZero) {
433
+ $bar.css('display', 'none');
434
+ } else {
435
+ if (isMultiple && allZero) {
436
+ $bar.css('background', 'transparent');
437
+ }
438
+ if (firstNonZeroIndex === -1) {
439
+ firstNonZeroIndex = index;
440
+ }
441
+ lastNonZeroIndex = index;
442
+ $bar.css({
443
+ display: 'block',
444
+ width: value + '%',
445
+ });
446
+ }
447
+
448
+ return parseFloat(value);
449
+ });
450
+ values.forEach(function (_, index) {
451
+ var $bar = $($bars[index]);
452
+ $bar.css({
453
+ borderTopLeftRadius: index === firstNonZeroIndex ? '' : '0',
454
+ borderBottomLeftRadius: index === firstNonZeroIndex ? '' : '0',
455
+ borderTopRightRadius: index === lastNonZeroIndex ? '' : '0',
456
+ borderBottomRightRadius: index === lastNonZeroIndex ? '' : '0',
457
+ });
458
+ });
459
+ $module
460
+ .attr('data-percent', percents)
461
+ ;
462
+ },
463
+ duration: function (duration) {
464
+ duration = duration || settings.duration;
465
+ duration = typeof duration === 'number'
466
+ ? duration + 'ms'
467
+ : duration;
468
+ module.verbose('Setting progress bar transition duration', duration);
469
+ $bars
470
+ .css({
471
+ 'transition-duration': duration,
472
+ })
473
+ ;
474
+ },
475
+ percent: function (percents) {
476
+ percents = module.helper.forceArray(percents).map(function (percent) {
477
+ percent = typeof percent === 'string'
478
+ ? +percent.replace('%', '')
479
+ : percent;
480
+
481
+ return settings.limitValues
482
+ ? Math.max(0, Math.min(100, percent))
483
+ : percent;
484
+ });
485
+ var hasTotal = module.has.total();
486
+ var totalPercent = module.helper.sum(percents);
487
+ var isMultipleValues = percents.length > 1 && hasTotal;
488
+ var sumTotal = module.helper.sum(module.helper.forceArray(module.value));
489
+ if (isMultipleValues && sumTotal > module.total) {
490
+ // Sum values instead of pecents to avoid precision issues when summing floats
491
+ module.error(error.sumExceedsTotal, sumTotal, module.total);
492
+ } else if (!isMultipleValues && totalPercent > 100) {
493
+ // Sum before rounding since sum of rounded may have error though sum of actual is fine
494
+ module.error(error.tooHigh, totalPercent);
495
+ } else if (totalPercent < 0) {
496
+ module.error(error.tooLow, totalPercent);
497
+ } else {
498
+ var autoPrecision = settings.precision > 0
499
+ ? settings.precision
500
+ : (isMultipleValues
501
+ ? module.helper.derivePrecision(Math.min.apply(null, module.value), module.total)
502
+ : 0);
503
+
504
+ // round display percentage
505
+ var roundedPercents = percents.map(function (percent) {
506
+ return autoPrecision > 0
507
+ ? Math.round(percent * (10 * autoPrecision)) / (10 * autoPrecision)
508
+ : Math.round(percent)
509
+ ;
510
+ });
511
+ module.percent = roundedPercents;
512
+ if (hasTotal) {
513
+ module.value = percents.map(function (percent) {
514
+ return autoPrecision > 0
515
+ ? Math.round((percent / 100) * module.total * (10 * autoPrecision)) / (10 * autoPrecision)
516
+ : Math.round((percent / 100) * module.total * 10) / 10;
517
+ });
518
+ }
519
+ module.set.barWidth(percents);
520
+ module.set.labelInterval();
521
+ }
522
+ settings.onChange.call(element, percents, module.value, module.total);
523
+ },
524
+ labelInterval: function () {
525
+ var
526
+ animationCallback = function () {
527
+ module.verbose('Bar finished animating, removing continuous label updates');
528
+ clearInterval(module.interval);
529
+ animating = false;
530
+ module.set.labels();
531
+ }
532
+ ;
533
+ clearInterval(module.interval);
534
+ module.bind.transitionEnd(animationCallback);
535
+ animating = true;
536
+ module.interval = setInterval(function () {
537
+ var
538
+ isInDOM = $.contains(document.documentElement, element)
539
+ ;
540
+ if (!isInDOM) {
541
+ clearInterval(module.interval);
542
+ animating = false;
543
+ }
544
+ module.set.labels();
545
+ }, settings.framerate);
546
+ },
547
+ labels: function () {
548
+ module.verbose('Setting both bar progress and outer label text');
549
+ module.set.barLabel();
550
+ module.set.state();
551
+ },
552
+ label: function (text) {
553
+ if (text) {
554
+ text = module.get.text(text);
555
+ module.verbose('Setting label to text', text);
556
+ $label.text(text);
557
+ }
558
+ },
559
+ state: function (percent) {
560
+ percent = percent !== undefined
561
+ ? percent
562
+ : module.helper.sum(module.percent);
563
+ if (percent === 100) {
564
+ if (settings.autoSuccess && $bars.length === 1 && !(module.is.warning() || module.is.error() || module.is.success())) {
565
+ module.set.success();
566
+ module.debug('Automatically triggering success at 100%');
567
+ } else {
568
+ module.verbose('Reached 100% removing active state');
569
+ module.remove.active();
570
+ module.remove.progressPoll();
571
+ }
572
+ } else if (percent > 0) {
573
+ module.verbose('Adjusting active progress bar label', percent);
574
+ module.set.active();
575
+ } else {
576
+ module.remove.active();
577
+ module.remove.warning();
578
+ module.remove.error();
579
+ module.remove.success();
580
+ module.set.label(settings.text.active);
581
+ }
582
+ },
583
+ barLabel: function (text) {
584
+ $progresses.each(function (index, element) {
585
+ var $progress = $(element);
586
+ if (text !== undefined) {
587
+ $progress.text(module.get.text(text, index));
588
+ } else if (settings.label === 'ratio' && module.has.total()) {
589
+ module.verbose('Adding ratio to bar label');
590
+ $progress.text(module.get.text(settings.text.ratio, index));
591
+ } else if (settings.label === 'percent') {
592
+ module.verbose('Adding percentage to bar label');
593
+ $progress.text(module.get.text(settings.text.percent, index));
594
+ }
595
+ });
596
+ },
597
+ active: function (text) {
598
+ text = text || settings.text.active;
599
+ module.debug('Setting active state');
600
+ if (settings.showActivity && !module.is.active()) {
601
+ $module.addClass(className.active);
602
+ }
603
+ module.remove.warning();
604
+ module.remove.error();
605
+ module.remove.success();
606
+ text = settings.onLabelUpdate('active', text, module.value, module.total);
607
+ if (text) {
608
+ module.set.label(text);
609
+ }
610
+ module.bind.transitionEnd(function () {
611
+ settings.onActive.call(element, module.value, module.total);
612
+ });
613
+ },
614
+ success: function (text, keepState) {
615
+ text = text || settings.text.success || settings.text.active;
616
+ module.debug('Setting success state');
617
+ $module.addClass(className.success);
618
+ module.remove.active();
619
+ module.remove.warning();
620
+ module.remove.error();
621
+ module.complete(keepState);
622
+ if (settings.text.success) {
623
+ text = settings.onLabelUpdate('success', text, module.value, module.total);
624
+ module.set.label(text);
625
+ } else {
626
+ text = settings.onLabelUpdate('active', text, module.value, module.total);
627
+ module.set.label(text);
628
+ }
629
+ module.bind.transitionEnd(function () {
630
+ settings.onSuccess.call(element, module.total);
631
+ });
632
+ },
633
+ warning: function (text, keepState) {
634
+ text = text || settings.text.warning;
635
+ module.debug('Setting warning state');
636
+ $module.addClass(className.warning);
637
+ module.remove.active();
638
+ module.remove.success();
639
+ module.remove.error();
640
+ module.complete(keepState);
641
+ text = settings.onLabelUpdate('warning', text, module.value, module.total);
642
+ if (text) {
643
+ module.set.label(text);
644
+ }
645
+ module.bind.transitionEnd(function () {
646
+ settings.onWarning.call(element, module.value, module.total);
647
+ });
648
+ },
649
+ error: function (text, keepState) {
650
+ text = text || settings.text.error;
651
+ module.debug('Setting error state');
652
+ $module.addClass(className.error);
653
+ module.remove.active();
654
+ module.remove.success();
655
+ module.remove.warning();
656
+ module.complete(keepState);
657
+ text = settings.onLabelUpdate('error', text, module.value, module.total);
658
+ if (text) {
659
+ module.set.label(text);
660
+ }
661
+ module.bind.transitionEnd(function () {
662
+ settings.onError.call(element, module.value, module.total);
663
+ });
664
+ },
665
+ total: function (totalValue) {
666
+ module.total = totalValue;
667
+ },
668
+ value: function (value) {
669
+ module.value = module.helper.forceArray(value);
670
+ },
671
+ progress: function (value) {
672
+ if (!module.has.progressPoll()) {
673
+ module.debug('First update in progress update interval, immediately updating', value);
674
+ module.update.progress(value);
675
+ module.create.progressPoll();
676
+ } else {
677
+ module.debug('Updated within interval, setting next update to use new value', value);
678
+ module.set.nextValue(value);
679
+ }
680
+ },
681
+ nextValue: function (value) {
682
+ module.nextValue = value;
683
+ },
684
+ },
685
+
686
+ update: {
687
+ toNextValue: function () {
688
+ var
689
+ nextValue = module.nextValue
690
+ ;
691
+ if (nextValue) {
692
+ module.debug('Update interval complete using last updated value', nextValue);
693
+ module.update.progress(nextValue);
694
+ module.remove.nextValue();
695
+ }
696
+ },
697
+ progress: function (values) {
698
+ var hasTotal = module.has.total();
699
+ if (hasTotal) {
700
+ module.set.value(values);
701
+ }
702
+ var percentCompletes = module.helper.forceArray(values).map(function (value) {
703
+ var
704
+ percentComplete
705
+ ;
706
+ value = module.get.numericValue(value);
707
+ if (value === false) {
708
+ module.error(error.nonNumeric, value);
709
+ }
710
+ value = module.get.normalizedValue(value);
711
+ if (hasTotal) {
712
+ percentComplete = module.total > 0 ? (value / module.total) * 100 : 100;
713
+ module.debug('Calculating percent complete from total', percentComplete);
714
+ } else {
715
+ percentComplete = value;
716
+ module.debug('Setting value to exact percentage value', percentComplete);
717
+ }
718
+
719
+ return percentComplete;
720
+ });
721
+ module.set.percent(percentCompletes);
722
+ },
723
+ },
724
+
725
+ setting: function (name, value) {
726
+ module.debug('Changing setting', name, value);
727
+ if ($.isPlainObject(name)) {
728
+ $.extend(true, settings, name);
729
+ } else if (value !== undefined) {
730
+ if ($.isPlainObject(settings[name])) {
731
+ $.extend(true, settings[name], value);
732
+ } else {
733
+ settings[name] = value;
734
+ }
735
+ } else {
736
+ return settings[name];
737
+ }
738
+ },
739
+ internal: function (name, value) {
740
+ if ($.isPlainObject(name)) {
741
+ $.extend(true, module, name);
742
+ } else if (value !== undefined) {
743
+ module[name] = value;
744
+ } else {
745
+ return module[name];
746
+ }
747
+ },
748
+ debug: function () {
749
+ if (!settings.silent && settings.debug) {
750
+ if (settings.performance) {
751
+ module.performance.log(arguments);
752
+ } else {
753
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
754
+ module.debug.apply(console, arguments);
755
+ }
756
+ }
757
+ },
758
+ verbose: function () {
759
+ if (!settings.silent && settings.verbose && settings.debug) {
760
+ if (settings.performance) {
761
+ module.performance.log(arguments);
762
+ } else {
763
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
764
+ module.verbose.apply(console, arguments);
765
+ }
766
+ }
767
+ },
768
+ error: function () {
769
+ if (!settings.silent) {
770
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
771
+ module.error.apply(console, arguments);
772
+ }
773
+ },
774
+ performance: {
775
+ log: function (message) {
776
+ var
777
+ currentTime,
778
+ executionTime,
779
+ previousTime
780
+ ;
781
+ if (settings.performance) {
782
+ currentTime = Date.now();
783
+ previousTime = time || currentTime;
784
+ executionTime = currentTime - previousTime;
785
+ time = currentTime;
786
+ performance.push({
787
+ Name: message[0],
788
+ Arguments: [].slice.call(message, 1) || '',
789
+ Element: element,
790
+ 'Execution Time': executionTime,
791
+ });
792
+ }
793
+ clearTimeout(module.performance.timer);
794
+ module.performance.timer = setTimeout(function () {
795
+ module.performance.display();
796
+ }, 500);
797
+ },
798
+ display: function () {
799
+ var
800
+ title = settings.name + ':',
801
+ totalTime = 0
802
+ ;
803
+ time = false;
804
+ clearTimeout(module.performance.timer);
805
+ $.each(performance, function (index, data) {
806
+ totalTime += data['Execution Time'];
807
+ });
808
+ title += ' ' + totalTime + 'ms';
809
+ if (performance.length > 0) {
810
+ console.groupCollapsed(title);
811
+ if (console.table) {
812
+ console.table(performance);
813
+ } else {
814
+ $.each(performance, function (index, data) {
815
+ console.log(data.Name + ': ' + data['Execution Time'] + 'ms');
816
+ });
817
+ }
818
+ console.groupEnd();
819
+ }
820
+ performance = [];
821
+ },
822
+ },
823
+ invoke: function (query, passedArguments, context) {
824
+ var
825
+ object = instance,
826
+ maxDepth,
827
+ found,
828
+ response
829
+ ;
830
+ passedArguments = passedArguments || queryArguments;
831
+ context = context || element;
832
+ if (typeof query === 'string' && object !== undefined) {
833
+ query = query.split(/[ .]/);
834
+ maxDepth = query.length - 1;
835
+ $.each(query, function (depth, value) {
836
+ var camelCaseValue = depth !== maxDepth
837
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
838
+ : query
839
+ ;
840
+ if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
841
+ object = object[camelCaseValue];
842
+ } else if (object[camelCaseValue] !== undefined) {
843
+ found = object[camelCaseValue];
844
+
845
+ return false;
846
+ } else if ($.isPlainObject(object[value]) && (depth !== maxDepth)) {
847
+ object = object[value];
848
+ } else if (object[value] !== undefined) {
849
+ found = object[value];
850
+
851
+ return false;
852
+ } else {
853
+ module.error(error.method, query);
854
+
855
+ return false;
856
+ }
857
+ });
858
+ }
859
+ if (isFunction(found)) {
860
+ response = found.apply(context, passedArguments);
861
+ } else if (found !== undefined) {
862
+ response = found;
863
+ }
864
+ if (Array.isArray(returnedValue)) {
865
+ returnedValue.push(response);
866
+ } else if (returnedValue !== undefined) {
867
+ returnedValue = [returnedValue, response];
868
+ } else if (response !== undefined) {
869
+ returnedValue = response;
870
+ }
871
+
872
+ return found;
873
+ },
874
+ };
875
+
876
+ if (methodInvoked) {
877
+ if (instance === undefined) {
878
+ module.initialize();
879
+ }
880
+ module.invoke(query);
881
+ } else {
882
+ if (instance !== undefined) {
883
+ instance.invoke('destroy');
884
+ }
885
+ module.initialize();
886
+ }
887
+ });
888
+
889
+ return returnedValue !== undefined
890
+ ? returnedValue
891
+ : this;
892
+ };
893
+
894
+ $.fn.progress.settings = {
895
+
896
+ name: 'Progress',
897
+ namespace: 'progress',
898
+
899
+ silent: false,
900
+ debug: false,
901
+ verbose: false,
902
+ performance: true,
903
+
904
+ random: {
905
+ min: 2,
906
+ max: 5,
907
+ },
908
+
909
+ duration: 300,
910
+
911
+ updateInterval: 'auto',
912
+
913
+ autoSuccess: true,
914
+ showActivity: true,
915
+ limitValues: true,
916
+
917
+ label: 'percent',
918
+ precision: 0,
919
+ framerate: 1000 / 30, /// 30 fps
920
+
921
+ percent: false,
922
+ total: false,
923
+ value: false,
924
+
925
+ // delay in ms for fail safe animation callback
926
+ failSafeDelay: 100,
927
+
928
+ onLabelUpdate: function (state, text, value, total) {
929
+ return text;
930
+ },
931
+ onChange: function (percent, value, total) {},
932
+ onSuccess: function (total) {},
933
+ onActive: function (value, total) {},
934
+ onError: function (value, total) {},
935
+ onWarning: function (value, total) {},
936
+
937
+ error: {
938
+ method: 'The method you called is not defined.',
939
+ nonNumeric: 'Progress value is non numeric',
940
+ tooHigh: 'Value specified is above 100%',
941
+ tooLow: 'Value specified is below 0%',
942
+ sumExceedsTotal: 'Sum of multiple values exceed total',
943
+ },
944
+
945
+ regExp: {
946
+ variable: /{\$*[\da-z]+}/gi,
947
+ },
948
+
949
+ metadata: {
950
+ percent: 'percent',
951
+ total: 'total',
952
+ value: 'value',
953
+ },
954
+
955
+ selector: {
956
+ bar: '> .bar',
957
+ label: '> .label',
958
+ progress: '.bar > .progress',
959
+ },
960
+
961
+ text: {
962
+ active: false,
963
+ error: false,
964
+ success: false,
965
+ warning: false,
966
+ percent: '{percent}%',
967
+ ratio: '{value} of {total}',
968
+ bars: [''],
969
+ },
970
+
971
+ className: {
972
+ active: 'active',
973
+ error: 'error',
974
+ success: 'success',
975
+ warning: 'warning',
976
+ },
977
+
978
+ };
979
+ })(jQuery, window, document);