fomantic-ui 2.9.1-beta.2 → 2.9.1-beta.20

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