rails-active-ui 0.3.0 → 0.3.2

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 (197) hide show
  1. checksums.yaml +4 -4
  2. data/app/javascript/ui/controllers/turbo_modal_controller.js +36 -0
  3. data/config/importmap.rb +1 -0
  4. data/formantic-ui/components/accordion.css +369 -0
  5. data/formantic-ui/components/accordion.js +595 -0
  6. data/formantic-ui/components/accordion.min.css +9 -0
  7. data/formantic-ui/components/accordion.min.js +11 -0
  8. data/formantic-ui/components/ad.css +264 -0
  9. data/formantic-ui/components/ad.min.css +10 -0
  10. data/formantic-ui/components/api.js +1225 -0
  11. data/formantic-ui/components/api.min.js +11 -0
  12. data/formantic-ui/components/breadcrumb.css +135 -0
  13. data/formantic-ui/components/breadcrumb.min.css +9 -0
  14. data/formantic-ui/components/button.css +4058 -0
  15. data/formantic-ui/components/button.min.css +9 -0
  16. data/formantic-ui/components/calendar.css +327 -0
  17. data/formantic-ui/components/calendar.js +2045 -0
  18. data/formantic-ui/components/calendar.min.css +9 -0
  19. data/formantic-ui/components/calendar.min.js +11 -0
  20. data/formantic-ui/components/card.css +1881 -0
  21. data/formantic-ui/components/card.min.css +9 -0
  22. data/formantic-ui/components/checkbox.css +785 -0
  23. data/formantic-ui/components/checkbox.js +888 -0
  24. data/formantic-ui/components/checkbox.min.css +9 -0
  25. data/formantic-ui/components/checkbox.min.js +11 -0
  26. data/formantic-ui/components/comment.css +283 -0
  27. data/formantic-ui/components/comment.min.css +9 -0
  28. data/formantic-ui/components/container.css +300 -0
  29. data/formantic-ui/components/container.min.css +9 -0
  30. data/formantic-ui/components/dimmer.css +367 -0
  31. data/formantic-ui/components/dimmer.js +732 -0
  32. data/formantic-ui/components/dimmer.min.css +9 -0
  33. data/formantic-ui/components/dimmer.min.js +11 -0
  34. data/formantic-ui/components/divider.css +287 -0
  35. data/formantic-ui/components/divider.min.css +9 -0
  36. data/formantic-ui/components/dropdown.css +2087 -0
  37. data/formantic-ui/components/dropdown.js +4432 -0
  38. data/formantic-ui/components/dropdown.min.css +9 -0
  39. data/formantic-ui/components/dropdown.min.js +11 -0
  40. data/formantic-ui/components/embed.css +155 -0
  41. data/formantic-ui/components/embed.js +688 -0
  42. data/formantic-ui/components/embed.min.css +9 -0
  43. data/formantic-ui/components/embed.min.js +11 -0
  44. data/formantic-ui/components/emoji.css +15311 -0
  45. data/formantic-ui/components/emoji.min.css +9 -0
  46. data/formantic-ui/components/feed.css +799 -0
  47. data/formantic-ui/components/feed.min.css +9 -0
  48. data/formantic-ui/components/flag.css +1149 -0
  49. data/formantic-ui/components/flag.min.css +9 -0
  50. data/formantic-ui/components/flyout.css +546 -0
  51. data/formantic-ui/components/flyout.js +1551 -0
  52. data/formantic-ui/components/flyout.min.css +9 -0
  53. data/formantic-ui/components/flyout.min.js +11 -0
  54. data/formantic-ui/components/form.css +1885 -0
  55. data/formantic-ui/components/form.js +2199 -0
  56. data/formantic-ui/components/form.min.css +9 -0
  57. data/formantic-ui/components/form.min.js +11 -0
  58. data/formantic-ui/components/grid.css +1952 -0
  59. data/formantic-ui/components/grid.min.css +9 -0
  60. data/formantic-ui/components/header.css +778 -0
  61. data/formantic-ui/components/header.min.css +9 -0
  62. data/formantic-ui/components/icon.css +7066 -0
  63. data/formantic-ui/components/icon.min.css +9 -0
  64. data/formantic-ui/components/image.css +315 -0
  65. data/formantic-ui/components/image.min.css +9 -0
  66. data/formantic-ui/components/input.css +1566 -0
  67. data/formantic-ui/components/input.min.css +9 -0
  68. data/formantic-ui/components/item.css +534 -0
  69. data/formantic-ui/components/item.min.css +9 -0
  70. data/formantic-ui/components/label.css +2114 -0
  71. data/formantic-ui/components/label.min.css +9 -0
  72. data/formantic-ui/components/list.css +955 -0
  73. data/formantic-ui/components/list.min.css +9 -0
  74. data/formantic-ui/components/loader.css +787 -0
  75. data/formantic-ui/components/loader.min.css +9 -0
  76. data/formantic-ui/components/menu.css +2131 -0
  77. data/formantic-ui/components/menu.min.css +9 -0
  78. data/formantic-ui/components/message.css +619 -0
  79. data/formantic-ui/components/message.min.css +9 -0
  80. data/formantic-ui/components/modal.css +779 -0
  81. data/formantic-ui/components/modal.js +1637 -0
  82. data/formantic-ui/components/modal.min.css +9 -0
  83. data/formantic-ui/components/modal.min.js +11 -0
  84. data/formantic-ui/components/nag.css +290 -0
  85. data/formantic-ui/components/nag.js +566 -0
  86. data/formantic-ui/components/nag.min.css +9 -0
  87. data/formantic-ui/components/nag.min.js +11 -0
  88. data/formantic-ui/components/placeholder.css +228 -0
  89. data/formantic-ui/components/placeholder.min.css +9 -0
  90. data/formantic-ui/components/popup.css +1184 -0
  91. data/formantic-ui/components/popup.js +1561 -0
  92. data/formantic-ui/components/popup.min.css +9 -0
  93. data/formantic-ui/components/popup.min.js +11 -0
  94. data/formantic-ui/components/progress.css +761 -0
  95. data/formantic-ui/components/progress.js +979 -0
  96. data/formantic-ui/components/progress.min.css +9 -0
  97. data/formantic-ui/components/progress.min.js +11 -0
  98. data/formantic-ui/components/rail.css +147 -0
  99. data/formantic-ui/components/rail.min.css +9 -0
  100. data/formantic-ui/components/rating.css +414 -0
  101. data/formantic-ui/components/rating.js +540 -0
  102. data/formantic-ui/components/rating.min.css +9 -0
  103. data/formantic-ui/components/rating.min.js +11 -0
  104. data/formantic-ui/components/reset.css +386 -0
  105. data/formantic-ui/components/reset.min.css +9 -0
  106. data/formantic-ui/components/reveal.css +277 -0
  107. data/formantic-ui/components/reveal.min.css +9 -0
  108. data/formantic-ui/components/search.css +541 -0
  109. data/formantic-ui/components/search.js +1641 -0
  110. data/formantic-ui/components/search.min.css +9 -0
  111. data/formantic-ui/components/search.min.js +11 -0
  112. data/formantic-ui/components/segment.css +1053 -0
  113. data/formantic-ui/components/segment.min.css +9 -0
  114. data/formantic-ui/components/shape.css +144 -0
  115. data/formantic-ui/components/shape.js +797 -0
  116. data/formantic-ui/components/shape.min.css +9 -0
  117. data/formantic-ui/components/shape.min.js +11 -0
  118. data/formantic-ui/components/sidebar.css +539 -0
  119. data/formantic-ui/components/sidebar.js +1054 -0
  120. data/formantic-ui/components/sidebar.min.css +9 -0
  121. data/formantic-ui/components/sidebar.min.js +11 -0
  122. data/formantic-ui/components/site.css +286 -0
  123. data/formantic-ui/components/site.js +455 -0
  124. data/formantic-ui/components/site.min.css +9 -0
  125. data/formantic-ui/components/site.min.js +11 -0
  126. data/formantic-ui/components/slider.css +926 -0
  127. data/formantic-ui/components/slider.js +1546 -0
  128. data/formantic-ui/components/slider.min.css +9 -0
  129. data/formantic-ui/components/slider.min.js +11 -0
  130. data/formantic-ui/components/state.js +697 -0
  131. data/formantic-ui/components/state.min.js +11 -0
  132. data/formantic-ui/components/statistic.css +586 -0
  133. data/formantic-ui/components/statistic.min.css +9 -0
  134. data/formantic-ui/components/step.css +1538 -0
  135. data/formantic-ui/components/step.min.css +9 -0
  136. data/formantic-ui/components/sticky.css +73 -0
  137. data/formantic-ui/components/sticky.js +917 -0
  138. data/formantic-ui/components/sticky.min.css +9 -0
  139. data/formantic-ui/components/sticky.min.js +11 -0
  140. data/formantic-ui/components/tab.css +84 -0
  141. data/formantic-ui/components/tab.js +967 -0
  142. data/formantic-ui/components/tab.min.css +9 -0
  143. data/formantic-ui/components/tab.min.js +11 -0
  144. data/formantic-ui/components/table.css +3473 -0
  145. data/formantic-ui/components/table.min.css +9 -0
  146. data/formantic-ui/components/text.css +155 -0
  147. data/formantic-ui/components/text.min.css +9 -0
  148. data/formantic-ui/components/toast.css +751 -0
  149. data/formantic-ui/components/toast.js +964 -0
  150. data/formantic-ui/components/toast.min.css +9 -0
  151. data/formantic-ui/components/toast.min.js +11 -0
  152. data/formantic-ui/components/transition.css +1148 -0
  153. data/formantic-ui/components/transition.js +1034 -0
  154. data/formantic-ui/components/transition.min.css +9 -0
  155. data/formantic-ui/components/transition.min.js +11 -0
  156. data/formantic-ui/components/visibility.js +1292 -0
  157. data/formantic-ui/components/visibility.min.js +11 -0
  158. data/formantic-ui/semantic.css +78485 -0
  159. data/formantic-ui/semantic.js +31036 -0
  160. data/formantic-ui/semantic.min.css +11 -0
  161. data/formantic-ui/semantic.min.js +11 -0
  162. data/formantic-ui/themes/basic/assets/fonts/LICENSE.txt +91 -0
  163. data/formantic-ui/themes/basic/assets/fonts/icons.woff +0 -0
  164. data/formantic-ui/themes/basic/assets/fonts/icons.woff2 +0 -0
  165. data/formantic-ui/themes/default/assets/fonts/LICENSE_Lato.txt +94 -0
  166. data/formantic-ui/themes/default/assets/fonts/LICENSE_icons.txt +165 -0
  167. data/formantic-ui/themes/default/assets/fonts/Lato-Bold.woff +0 -0
  168. data/formantic-ui/themes/default/assets/fonts/Lato-Bold.woff2 +0 -0
  169. data/formantic-ui/themes/default/assets/fonts/Lato-BoldItalic.woff +0 -0
  170. data/formantic-ui/themes/default/assets/fonts/Lato-BoldItalic.woff2 +0 -0
  171. data/formantic-ui/themes/default/assets/fonts/Lato-Italic.woff +0 -0
  172. data/formantic-ui/themes/default/assets/fonts/Lato-Italic.woff2 +0 -0
  173. data/formantic-ui/themes/default/assets/fonts/Lato-Regular.woff +0 -0
  174. data/formantic-ui/themes/default/assets/fonts/Lato-Regular.woff2 +0 -0
  175. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Bold.woff +0 -0
  176. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Bold.woff2 +0 -0
  177. data/formantic-ui/themes/default/assets/fonts/LatoLatin-BoldItalic.woff +0 -0
  178. data/formantic-ui/themes/default/assets/fonts/LatoLatin-BoldItalic.woff2 +0 -0
  179. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Italic.woff +0 -0
  180. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Italic.woff2 +0 -0
  181. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Regular.woff +0 -0
  182. data/formantic-ui/themes/default/assets/fonts/LatoLatin-Regular.woff2 +0 -0
  183. data/formantic-ui/themes/default/assets/fonts/brand-icons.woff +0 -0
  184. data/formantic-ui/themes/default/assets/fonts/brand-icons.woff2 +0 -0
  185. data/formantic-ui/themes/default/assets/fonts/icons.woff +0 -0
  186. data/formantic-ui/themes/default/assets/fonts/icons.woff2 +0 -0
  187. data/formantic-ui/themes/default/assets/fonts/outline-icons.woff +0 -0
  188. data/formantic-ui/themes/default/assets/fonts/outline-icons.woff2 +0 -0
  189. data/formantic-ui/themes/famfamfam/assets/images/flags.png +0 -0
  190. data/formantic-ui/themes/github/assets/fonts/LICENSE.txt +94 -0
  191. data/formantic-ui/themes/github/assets/fonts/octicons.woff +0 -0
  192. data/formantic-ui/themes/github/assets/fonts/octicons.woff2 +0 -0
  193. data/formantic-ui/themes/material/assets/fonts/LICENSE.txt +202 -0
  194. data/formantic-ui/themes/material/assets/fonts/icons.woff +0 -0
  195. data/formantic-ui/themes/material/assets/fonts/icons.woff2 +0 -0
  196. data/lib/ui/version.rb +1 -1
  197. metadata +194 -1
@@ -0,0 +1,697 @@
1
+ /*!
2
+ * # Fomantic-UI 2.9.4 - State
3
+ * https://github.com/fomantic/Fomantic-UI/
4
+ *
5
+ *
6
+ * Released under the MIT license
7
+ * https://opensource.org/licenses/MIT
8
+ *
9
+ */
10
+
11
+ (function ($, window, document) {
12
+ 'use strict';
13
+
14
+ function isFunction(obj) {
15
+ return typeof obj === 'function' && typeof obj.nodeType !== 'number';
16
+ }
17
+
18
+ window = window !== undefined && window.Math === Math
19
+ ? window
20
+ : globalThis;
21
+
22
+ $.fn.state = function (parameters) {
23
+ var
24
+ $allModules = $(this),
25
+
26
+ time = Date.now(),
27
+ performance = [],
28
+
29
+ query = arguments[0],
30
+ methodInvoked = typeof query === 'string',
31
+ queryArguments = [].slice.call(arguments, 1),
32
+ contextCheck = function (context, win) {
33
+ var $context;
34
+ if ([window, document].indexOf(context) >= 0) {
35
+ $context = $(context);
36
+ } else {
37
+ $context = $(win.document).find(context);
38
+ if ($context.length === 0) {
39
+ $context = win.frameElement ? contextCheck(context, win.parent) : window;
40
+ }
41
+ }
42
+
43
+ return $context;
44
+ },
45
+ returnedValue
46
+ ;
47
+ $allModules.each(function () {
48
+ var
49
+ settings = $.isPlainObject(parameters)
50
+ ? $.extend(true, {}, $.fn.state.settings, parameters)
51
+ : $.extend({}, $.fn.state.settings),
52
+
53
+ error = settings.error,
54
+ metadata = settings.metadata,
55
+ className = settings.className,
56
+ namespace = settings.namespace,
57
+ states = settings.states,
58
+ text = settings.text,
59
+
60
+ eventNamespace = '.' + namespace,
61
+ moduleNamespace = namespace + '-module',
62
+
63
+ $module = $(this),
64
+ $context = settings.context ? contextCheck(settings.context, window) : $module,
65
+
66
+ element = this,
67
+ instance = $module.data(moduleNamespace),
68
+
69
+ module
70
+ ;
71
+ module = {
72
+
73
+ initialize: function () {
74
+ module.verbose('Initializing module');
75
+
76
+ // allow module to guess desired state based on element
77
+ if (settings.automatic) {
78
+ module.add.defaults();
79
+ }
80
+
81
+ // bind events with delegated events
82
+ $context
83
+ .on('mouseenter' + eventNamespace, module.change.text)
84
+ .on('mouseleave' + eventNamespace, module.reset.text)
85
+ .on('click' + eventNamespace, module.toggle.state)
86
+ ;
87
+ module.instantiate();
88
+ },
89
+
90
+ instantiate: function () {
91
+ module.verbose('Storing instance of module', module);
92
+ instance = module;
93
+ $module
94
+ .data(moduleNamespace, module)
95
+ ;
96
+ },
97
+
98
+ destroy: function () {
99
+ module.verbose('Destroying previous module', instance);
100
+ $context
101
+ .off(eventNamespace)
102
+ ;
103
+ $module
104
+ .removeData(metadata.storedText)
105
+ .removeData(moduleNamespace)
106
+ ;
107
+ },
108
+
109
+ refresh: function () {
110
+ module.verbose('Refreshing selector cache');
111
+ $module = $(element);
112
+ },
113
+
114
+ add: {
115
+ defaults: function () {
116
+ var
117
+ userStates = parameters && $.isPlainObject(parameters.states)
118
+ ? parameters.states
119
+ : {}
120
+ ;
121
+ $.each(settings.defaults, function (type, typeStates) {
122
+ if (module.is[type] !== undefined && module.is[type]()) {
123
+ module.verbose('Adding default states', type, element);
124
+ $.extend(settings.states, typeStates, userStates);
125
+ }
126
+ });
127
+ },
128
+ },
129
+
130
+ is: {
131
+
132
+ active: function () {
133
+ return $module.hasClass(className.active);
134
+ },
135
+ loading: function () {
136
+ return $module.hasClass(className.loading);
137
+ },
138
+ inactive: function () {
139
+ return !$module.hasClass(className.active);
140
+ },
141
+ state: function (state) {
142
+ if (className[state] === undefined) {
143
+ return false;
144
+ }
145
+
146
+ return $module.hasClass(className[state]);
147
+ },
148
+
149
+ enabled: function () {
150
+ return !$module.is(settings.filter.active);
151
+ },
152
+ disabled: function () {
153
+ return $module.is(settings.filter.active);
154
+ },
155
+ textEnabled: function () {
156
+ return !$module.is(settings.filter.text);
157
+ },
158
+
159
+ // definitions for automatic type detection
160
+ button: function () {
161
+ return $module.is('.button:not(a, .submit)');
162
+ },
163
+ input: function () {
164
+ return $module.is('input');
165
+ },
166
+ progress: function () {
167
+ return $module.is('.ui.progress');
168
+ },
169
+ },
170
+
171
+ allow: function (state) {
172
+ module.debug('Now allowing state', state);
173
+ states[state] = true;
174
+ },
175
+ disallow: function (state) {
176
+ module.debug('No longer allowing', state);
177
+ states[state] = false;
178
+ },
179
+
180
+ allows: function (state) {
181
+ return states[state] || false;
182
+ },
183
+
184
+ enable: function () {
185
+ $module.removeClass(className.disabled);
186
+ },
187
+
188
+ disable: function () {
189
+ $module.addClass(className.disabled);
190
+ },
191
+
192
+ setState: function (state) {
193
+ if (module.allows(state)) {
194
+ $module.addClass(className[state]);
195
+ }
196
+ },
197
+
198
+ removeState: function (state) {
199
+ if (module.allows(state)) {
200
+ $module.removeClass(className[state]);
201
+ }
202
+ },
203
+
204
+ toggle: {
205
+ state: function () {
206
+ var
207
+ apiRequest,
208
+ requestCancelled
209
+ ;
210
+ if (module.allows('active') && module.is.enabled()) {
211
+ module.refresh();
212
+ if ($.fn.api !== undefined) {
213
+ apiRequest = $module.api('get request');
214
+ requestCancelled = $module.api('was cancelled');
215
+ if (requestCancelled) {
216
+ module.debug('API Request cancelled by beforesend');
217
+ settings.activateTest = function () {
218
+ return false;
219
+ };
220
+ settings.deactivateTest = function () {
221
+ return false;
222
+ };
223
+ } else if (apiRequest) {
224
+ module.listenTo(apiRequest);
225
+
226
+ return;
227
+ }
228
+ }
229
+ module.change.state();
230
+ }
231
+ },
232
+ },
233
+
234
+ listenTo: function (apiRequest) {
235
+ module.debug('API request detected, waiting for state signal', apiRequest);
236
+ if (apiRequest) {
237
+ if (text.loading) {
238
+ module.update.text(text.loading);
239
+ }
240
+ $.when(apiRequest)
241
+ .then(function () {
242
+ if (apiRequest.state() === 'resolved') {
243
+ module.debug('API request succeeded');
244
+ settings.activateTest = function () {
245
+ return true;
246
+ };
247
+ settings.deactivateTest = function () {
248
+ return true;
249
+ };
250
+ } else {
251
+ module.debug('API request failed');
252
+ settings.activateTest = function () {
253
+ return false;
254
+ };
255
+ settings.deactivateTest = function () {
256
+ return false;
257
+ };
258
+ }
259
+ module.change.state();
260
+ })
261
+ ;
262
+ }
263
+ },
264
+
265
+ // checks whether active/inactive state can be given
266
+ change: {
267
+
268
+ state: function () {
269
+ module.debug('Determining state change direction');
270
+ // inactive to active change
271
+ if (module.is.inactive()) {
272
+ module.activate();
273
+ } else {
274
+ module.deactivate();
275
+ }
276
+ if (settings.sync) {
277
+ module.sync();
278
+ }
279
+ settings.onChange.call(element);
280
+ },
281
+
282
+ text: function () {
283
+ if (module.is.textEnabled()) {
284
+ if (module.is.disabled()) {
285
+ module.verbose('Changing text to disabled text', text.hover);
286
+ module.update.text(text.disabled);
287
+ } else if (module.is.active()) {
288
+ if (text.hover) {
289
+ module.verbose('Changing text to hover text', text.hover);
290
+ module.update.text(text.hover);
291
+ } else if (text.deactivate) {
292
+ module.verbose('Changing text to deactivating text', text.deactivate);
293
+ module.update.text(text.deactivate);
294
+ }
295
+ } else {
296
+ if (text.hover) {
297
+ module.verbose('Changing text to hover text', text.hover);
298
+ module.update.text(text.hover);
299
+ } else if (text.activate) {
300
+ module.verbose('Changing text to activating text', text.activate);
301
+ module.update.text(text.activate);
302
+ }
303
+ }
304
+ }
305
+ },
306
+
307
+ },
308
+
309
+ activate: function () {
310
+ if (settings.activateTest.call(element)) {
311
+ module.debug('Setting state to active');
312
+ $module
313
+ .addClass(className.active)
314
+ ;
315
+ module.update.text(text.active);
316
+ settings.onActivate.call(element);
317
+ }
318
+ },
319
+
320
+ deactivate: function () {
321
+ if (settings.deactivateTest.call(element)) {
322
+ module.debug('Setting state to inactive');
323
+ $module
324
+ .removeClass(className.active)
325
+ ;
326
+ module.update.text(text.inactive);
327
+ settings.onDeactivate.call(element);
328
+ }
329
+ },
330
+
331
+ sync: function () {
332
+ module.verbose('Syncing other buttons to current state');
333
+ if (module.is.active()) {
334
+ $allModules
335
+ .not($module)
336
+ .state('activate')
337
+ ;
338
+ } else {
339
+ $allModules
340
+ .not($module)
341
+ .state('deactivate')
342
+ ;
343
+ }
344
+ },
345
+
346
+ get: {
347
+ text: function () {
348
+ return settings.selector.text
349
+ ? $module.find(settings.selector.text).text()
350
+ : $module.html();
351
+ },
352
+ textFor: function (state) {
353
+ return text[state] || false;
354
+ },
355
+ },
356
+
357
+ flash: {
358
+ text: function (text, duration, callback) {
359
+ var
360
+ previousText = module.get.text();
361
+ module.debug('Flashing text message', text, duration);
362
+ text = text || settings.text.flash;
363
+ duration = duration || settings.flashDuration;
364
+ callback = callback || function () {};
365
+ module.update.text(text);
366
+ setTimeout(function () {
367
+ module.update.text(previousText);
368
+ callback.call(element);
369
+ }, duration);
370
+ },
371
+ },
372
+
373
+ reset: {
374
+ // on mouseout sets text to previous value
375
+ text: function () {
376
+ var
377
+ activeText = text.active || $module.data(metadata.storedText),
378
+ inactiveText = text.inactive || $module.data(metadata.storedText)
379
+ ;
380
+ if (module.is.textEnabled()) {
381
+ if (module.is.active() && activeText) {
382
+ module.verbose('Resetting active text', activeText);
383
+ module.update.text(activeText);
384
+ } else if (inactiveText) {
385
+ module.verbose('Resetting inactive text', activeText);
386
+ module.update.text(inactiveText);
387
+ }
388
+ }
389
+ },
390
+ },
391
+
392
+ update: {
393
+ text: function (text) {
394
+ var
395
+ currentText = module.get.text();
396
+ if (text && text !== currentText) {
397
+ module.debug('Updating text', text);
398
+ if (settings.selector.text) {
399
+ $module
400
+ .data(metadata.storedText, text)
401
+ .find(settings.selector.text)
402
+ .text(text)
403
+ ;
404
+ } else {
405
+ $module
406
+ .data(metadata.storedText, text)
407
+ .html(text)
408
+ ;
409
+ }
410
+ } else {
411
+ module.debug('Text is already set, ignoring update', text);
412
+ }
413
+ },
414
+ },
415
+
416
+ setting: function (name, value) {
417
+ module.debug('Changing setting', name, value);
418
+ if ($.isPlainObject(name)) {
419
+ $.extend(true, settings, name);
420
+ } else if (value !== undefined) {
421
+ if ($.isPlainObject(settings[name])) {
422
+ $.extend(true, settings[name], value);
423
+ } else {
424
+ settings[name] = value;
425
+ }
426
+ } else {
427
+ return settings[name];
428
+ }
429
+ },
430
+ internal: function (name, value) {
431
+ if ($.isPlainObject(name)) {
432
+ $.extend(true, module, name);
433
+ } else if (value !== undefined) {
434
+ module[name] = value;
435
+ } else {
436
+ return module[name];
437
+ }
438
+ },
439
+ debug: function () {
440
+ if (!settings.silent && settings.debug) {
441
+ if (settings.performance) {
442
+ module.performance.log(arguments);
443
+ } else {
444
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
445
+ module.debug.apply(console, arguments);
446
+ }
447
+ }
448
+ },
449
+ verbose: function () {
450
+ if (!settings.silent && settings.verbose && settings.debug) {
451
+ if (settings.performance) {
452
+ module.performance.log(arguments);
453
+ } else {
454
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
455
+ module.verbose.apply(console, arguments);
456
+ }
457
+ }
458
+ },
459
+ error: function () {
460
+ if (!settings.silent) {
461
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
462
+ module.error.apply(console, arguments);
463
+ }
464
+ },
465
+ performance: {
466
+ log: function (message) {
467
+ var
468
+ currentTime,
469
+ executionTime,
470
+ previousTime
471
+ ;
472
+ if (settings.performance) {
473
+ currentTime = Date.now();
474
+ previousTime = time || currentTime;
475
+ executionTime = currentTime - previousTime;
476
+ time = currentTime;
477
+ performance.push({
478
+ Name: message[0],
479
+ Arguments: [].slice.call(message, 1) || '',
480
+ Element: element,
481
+ 'Execution Time': executionTime,
482
+ });
483
+ }
484
+ clearTimeout(module.performance.timer);
485
+ module.performance.timer = setTimeout(function () {
486
+ module.performance.display();
487
+ }, 500);
488
+ },
489
+ display: function () {
490
+ var
491
+ title = settings.name + ':',
492
+ totalTime = 0
493
+ ;
494
+ time = false;
495
+ clearTimeout(module.performance.timer);
496
+ $.each(performance, function (index, data) {
497
+ totalTime += data['Execution Time'];
498
+ });
499
+ title += ' ' + totalTime + 'ms';
500
+ if (performance.length > 0) {
501
+ console.groupCollapsed(title);
502
+ if (console.table) {
503
+ console.table(performance);
504
+ } else {
505
+ $.each(performance, function (index, data) {
506
+ console.log(data.Name + ': ' + data['Execution Time'] + 'ms');
507
+ });
508
+ }
509
+ console.groupEnd();
510
+ }
511
+ performance = [];
512
+ },
513
+ },
514
+ invoke: function (query, passedArguments, context) {
515
+ var
516
+ object = instance,
517
+ maxDepth,
518
+ found,
519
+ response
520
+ ;
521
+ passedArguments = passedArguments || queryArguments;
522
+ context = context || element;
523
+ if (typeof query === 'string' && object !== undefined) {
524
+ query = query.split(/[ .]/);
525
+ maxDepth = query.length - 1;
526
+ $.each(query, function (depth, value) {
527
+ var camelCaseValue = depth !== maxDepth
528
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
529
+ : query
530
+ ;
531
+ if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
532
+ object = object[camelCaseValue];
533
+ } else if (object[camelCaseValue] !== undefined) {
534
+ found = object[camelCaseValue];
535
+
536
+ return false;
537
+ } else if ($.isPlainObject(object[value]) && (depth !== maxDepth)) {
538
+ object = object[value];
539
+ } else if (object[value] !== undefined) {
540
+ found = object[value];
541
+
542
+ return false;
543
+ } else {
544
+ module.error(error.method, query);
545
+
546
+ return false;
547
+ }
548
+ });
549
+ }
550
+ if (isFunction(found)) {
551
+ response = found.apply(context, passedArguments);
552
+ } else if (found !== undefined) {
553
+ response = found;
554
+ }
555
+ if (Array.isArray(returnedValue)) {
556
+ returnedValue.push(response);
557
+ } else if (returnedValue !== undefined) {
558
+ returnedValue = [returnedValue, response];
559
+ } else if (response !== undefined) {
560
+ returnedValue = response;
561
+ }
562
+
563
+ return found;
564
+ },
565
+ };
566
+
567
+ if (methodInvoked) {
568
+ if (instance === undefined) {
569
+ module.initialize();
570
+ }
571
+ module.invoke(query);
572
+ } else {
573
+ if (instance !== undefined) {
574
+ instance.invoke('destroy');
575
+ }
576
+ module.initialize();
577
+ }
578
+ });
579
+
580
+ return returnedValue !== undefined
581
+ ? returnedValue
582
+ : this;
583
+ };
584
+
585
+ $.fn.state.settings = {
586
+
587
+ // module info
588
+ name: 'State',
589
+
590
+ // debug output
591
+ debug: false,
592
+
593
+ // verbose debug output
594
+ verbose: false,
595
+
596
+ // namespace for events
597
+ namespace: 'state',
598
+
599
+ // debug data includes performance
600
+ performance: true,
601
+
602
+ // callback occurs on state change
603
+ onActivate: function () {},
604
+ onDeactivate: function () {},
605
+ onChange: function () {},
606
+
607
+ // state test functions
608
+ activateTest: function () {
609
+ return true;
610
+ },
611
+ deactivateTest: function () {
612
+ return true;
613
+ },
614
+
615
+ // whether to automatically map default states
616
+ automatic: true,
617
+
618
+ // activate / deactivate changes all elements instantiated at same time
619
+ sync: false,
620
+
621
+ // default flash text duration, used for temporarily changing text of an element
622
+ flashDuration: 1000,
623
+
624
+ // selector filter
625
+ filter: {
626
+ text: '.loading, .disabled',
627
+ active: '.disabled',
628
+ },
629
+
630
+ context: false,
631
+
632
+ // error
633
+ error: {
634
+ method: 'The method you called is not defined.',
635
+ },
636
+
637
+ // metadata
638
+ metadata: {
639
+ promise: 'promise',
640
+ storedText: 'stored-text',
641
+ },
642
+
643
+ // change class on state
644
+ className: {
645
+ active: 'active',
646
+ disabled: 'disabled',
647
+ error: 'error',
648
+ loading: 'loading',
649
+ success: 'success',
650
+ warning: 'warning',
651
+ },
652
+
653
+ selector: {
654
+ // selector for text node
655
+ text: false,
656
+ },
657
+
658
+ defaults: {
659
+ input: {
660
+ disabled: true,
661
+ loading: true,
662
+ active: true,
663
+ },
664
+ button: {
665
+ disabled: true,
666
+ loading: true,
667
+ active: true,
668
+ },
669
+ progress: {
670
+ active: true,
671
+ success: true,
672
+ warning: true,
673
+ error: true,
674
+ },
675
+ },
676
+
677
+ states: {
678
+ active: true,
679
+ disabled: true,
680
+ error: true,
681
+ loading: true,
682
+ success: true,
683
+ warning: true,
684
+ },
685
+
686
+ text: {
687
+ disabled: false,
688
+ flash: false,
689
+ hover: false,
690
+ active: false,
691
+ inactive: false,
692
+ activate: false,
693
+ deactivate: false,
694
+ },
695
+
696
+ };
697
+ })(jQuery, window, document);