fomantic-ui-sass 2.9.0 → 2.9.2

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