rails-active-ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +6 -0
  3. data/app/assets/stylesheets.css +73555 -0
  4. data/app/components/accordion_component.rb +34 -0
  5. data/app/components/ad_component.rb +28 -0
  6. data/app/components/api_component.rb +24 -0
  7. data/app/components/breadcrumb_component.rb +26 -0
  8. data/app/components/button_component.rb +49 -0
  9. data/app/components/calendar_component.rb +34 -0
  10. data/app/components/card_component.rb +56 -0
  11. data/app/components/checkbox_component.rb +41 -0
  12. data/app/components/column_component.rb +62 -0
  13. data/app/components/comment_component.rb +45 -0
  14. data/app/components/concerns/alignable.rb +21 -0
  15. data/app/components/concerns/attachable.rb +16 -0
  16. data/app/components/concerns/orientable.rb +21 -0
  17. data/app/components/concerns/positionable.rb +21 -0
  18. data/app/components/concerns/sizeable.rb +18 -0
  19. data/app/components/container_component.rb +23 -0
  20. data/app/components/dimmer_component.rb +30 -0
  21. data/app/components/divider_component.rb +30 -0
  22. data/app/components/dropdown_component.rb +63 -0
  23. data/app/components/embed_component.rb +32 -0
  24. data/app/components/emoji_component.rb +15 -0
  25. data/app/components/feed_component.rb +22 -0
  26. data/app/components/flag_component.rb +15 -0
  27. data/app/components/flyout_component.rb +41 -0
  28. data/app/components/form_component.rb +39 -0
  29. data/app/components/grid_component.rb +85 -0
  30. data/app/components/h_stack_component.rb +67 -0
  31. data/app/components/header_component.rb +60 -0
  32. data/app/components/icon_component.rb +41 -0
  33. data/app/components/image_component.rb +46 -0
  34. data/app/components/input_component.rb +52 -0
  35. data/app/components/item_component.rb +39 -0
  36. data/app/components/item_group_component.rb +30 -0
  37. data/app/components/label_component.rb +49 -0
  38. data/app/components/link_component.rb +23 -0
  39. data/app/components/list_component.rb +39 -0
  40. data/app/components/loader_component.rb +33 -0
  41. data/app/components/menu_component.rb +64 -0
  42. data/app/components/menu_item_component.rb +52 -0
  43. data/app/components/message_component.rb +54 -0
  44. data/app/components/modal_component.rb +50 -0
  45. data/app/components/nag_component.rb +25 -0
  46. data/app/components/overlay_component.rb +16 -0
  47. data/app/components/placeholder_component.rb +39 -0
  48. data/app/components/popup_component.rb +31 -0
  49. data/app/components/progress_component.rb +48 -0
  50. data/app/components/pusher_component.rb +18 -0
  51. data/app/components/rail_component.rb +31 -0
  52. data/app/components/rating_component.rb +41 -0
  53. data/app/components/reset_component.rb +12 -0
  54. data/app/components/reveal_component.rb +39 -0
  55. data/app/components/row_component.rb +39 -0
  56. data/app/components/search_component.rb +44 -0
  57. data/app/components/segment_component.rb +57 -0
  58. data/app/components/segment_group_component.rb +36 -0
  59. data/app/components/shape_component.rb +25 -0
  60. data/app/components/sidebar_component.rb +33 -0
  61. data/app/components/site_component.rb +12 -0
  62. data/app/components/slider_component.rb +46 -0
  63. data/app/components/state_component.rb +25 -0
  64. data/app/components/statistic_component.rb +43 -0
  65. data/app/components/step_component.rb +56 -0
  66. data/app/components/step_group_component.rb +38 -0
  67. data/app/components/sticky_component.rb +22 -0
  68. data/app/components/sub_header_component.rb +15 -0
  69. data/app/components/sub_menu_component.rb +24 -0
  70. data/app/components/tab_component.rb +24 -0
  71. data/app/components/table_cell_component.rb +60 -0
  72. data/app/components/table_component.rb +160 -0
  73. data/app/components/table_row_component.rb +43 -0
  74. data/app/components/text_component.rb +73 -0
  75. data/app/components/toast_component.rb +36 -0
  76. data/app/components/transition_component.rb +32 -0
  77. data/app/components/v_stack_component.rb +31 -0
  78. data/app/components/visibility_component.rb +22 -0
  79. data/app/helpers/component_helper.rb +109 -0
  80. data/app/helpers/fui_helper.rb +53 -0
  81. data/app/javascript/accordion.js +547 -0
  82. data/app/javascript/accordion.min.js +11 -0
  83. data/app/javascript/api.js +1112 -0
  84. data/app/javascript/api.min.js +11 -0
  85. data/app/javascript/calendar.js +1960 -0
  86. data/app/javascript/calendar.min.js +11 -0
  87. data/app/javascript/checkbox.js +819 -0
  88. data/app/javascript/checkbox.min.js +11 -0
  89. data/app/javascript/dimmer.js +686 -0
  90. data/app/javascript/dimmer.min.js +11 -0
  91. data/app/javascript/dropdown.js +4019 -0
  92. data/app/javascript/dropdown.min.js +11 -0
  93. data/app/javascript/embed.js +646 -0
  94. data/app/javascript/embed.min.js +11 -0
  95. data/app/javascript/flyout.js +1405 -0
  96. data/app/javascript/flyout.min.js +11 -0
  97. data/app/javascript/form.js +2070 -0
  98. data/app/javascript/form.min.js +11 -0
  99. data/app/javascript/jquery.js +10716 -0
  100. data/app/javascript/jquery.min.js +2 -0
  101. data/app/javascript/modal.js +1507 -0
  102. data/app/javascript/modal.min.js +11 -0
  103. data/app/javascript/nag.js +522 -0
  104. data/app/javascript/nag.min.js +11 -0
  105. data/app/javascript/popup.js +1457 -0
  106. data/app/javascript/popup.min.js +11 -0
  107. data/app/javascript/progress.js +922 -0
  108. data/app/javascript/progress.min.js +11 -0
  109. data/app/javascript/rating.js +496 -0
  110. data/app/javascript/rating.min.js +11 -0
  111. data/app/javascript/search.js +1519 -0
  112. data/app/javascript/search.min.js +11 -0
  113. data/app/javascript/shape.js +721 -0
  114. data/app/javascript/shape.min.js +11 -0
  115. data/app/javascript/sidebar.js +952 -0
  116. data/app/javascript/sidebar.min.js +11 -0
  117. data/app/javascript/site.js +415 -0
  118. data/app/javascript/site.min.js +11 -0
  119. data/app/javascript/slider.js +1449 -0
  120. data/app/javascript/slider.min.js +11 -0
  121. data/app/javascript/state.js +653 -0
  122. data/app/javascript/state.min.js +11 -0
  123. data/app/javascript/sticky.js +852 -0
  124. data/app/javascript/sticky.min.js +11 -0
  125. data/app/javascript/tab.js +867 -0
  126. data/app/javascript/tab.min.js +11 -0
  127. data/app/javascript/toast.js +916 -0
  128. data/app/javascript/toast.min.js +11 -0
  129. data/app/javascript/transition.js +955 -0
  130. data/app/javascript/transition.min.js +11 -0
  131. data/app/javascript/ui/controllers/fui_accordion_controller.js +45 -0
  132. data/app/javascript/ui/controllers/fui_api_controller.js +80 -0
  133. data/app/javascript/ui/controllers/fui_calendar_controller.js +66 -0
  134. data/app/javascript/ui/controllers/fui_checkbox_controller.js +48 -0
  135. data/app/javascript/ui/controllers/fui_dimmer_controller.js +45 -0
  136. data/app/javascript/ui/controllers/fui_dropdown_controller.js +68 -0
  137. data/app/javascript/ui/controllers/fui_embed_controller.js +49 -0
  138. data/app/javascript/ui/controllers/fui_flyout_controller.js +49 -0
  139. data/app/javascript/ui/controllers/fui_form_controller.js +62 -0
  140. data/app/javascript/ui/controllers/fui_modal_controller.js +61 -0
  141. data/app/javascript/ui/controllers/fui_nag_controller.js +52 -0
  142. data/app/javascript/ui/controllers/fui_popup_controller.js +58 -0
  143. data/app/javascript/ui/controllers/fui_progress_controller.js +60 -0
  144. data/app/javascript/ui/controllers/fui_rating_controller.js +49 -0
  145. data/app/javascript/ui/controllers/fui_search_controller.js +76 -0
  146. data/app/javascript/ui/controllers/fui_shape_controller.js +45 -0
  147. data/app/javascript/ui/controllers/fui_sidebar_controller.js +48 -0
  148. data/app/javascript/ui/controllers/fui_site_controller.js +29 -0
  149. data/app/javascript/ui/controllers/fui_slider_controller.js +53 -0
  150. data/app/javascript/ui/controllers/fui_state_controller.js +63 -0
  151. data/app/javascript/ui/controllers/fui_sticky_controller.js +50 -0
  152. data/app/javascript/ui/controllers/fui_tab_controller.js +57 -0
  153. data/app/javascript/ui/controllers/fui_toast_controller.js +60 -0
  154. data/app/javascript/ui/controllers/fui_transition_controller.js +60 -0
  155. data/app/javascript/ui/controllers/fui_visibility_controller.js +55 -0
  156. data/app/javascript/ui/index.js +114 -0
  157. data/app/javascript/visibility.js +1196 -0
  158. data/app/javascript/visibility.min.js +11 -0
  159. data/app/lib/component.rb +63 -0
  160. data/config/importmap.rb +27 -0
  161. data/config/initializers/ruby_template_handler.rb +31 -0
  162. data/config/routes.rb +2 -0
  163. data/lib/tasks/ui_tasks.rake +4 -0
  164. data/lib/ui/engine.rb +27 -0
  165. data/lib/ui/version.rb +3 -0
  166. data/lib/ui.rb +6 -0
  167. metadata +220 -0
@@ -0,0 +1,1449 @@
1
+ /*!
2
+ * # Fomantic-UI 2.9.4 - Slider
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.slider = function (...args) {
23
+ const $allModules = $(this);
24
+ const $document = $(document);
25
+ const $window = $(window);
26
+
27
+ let time = Date.now();
28
+ let performance = [];
29
+
30
+ const parameters = args[0];
31
+ const methodInvoked = typeof parameters === 'string';
32
+ const queryArguments = args.slice(1);
33
+
34
+ const SINGLE_STEP = 1;
35
+ const BIG_STEP = 2;
36
+ const NO_STEP = 0;
37
+ const SINGLE_BACKSTEP = -1;
38
+ const BIG_BACKSTEP = -2;
39
+
40
+ // Used to manage document bound events.
41
+ // Use this so that we can distinguish between which document events are bound to which range.
42
+ let currentRange = 0;
43
+
44
+ let returnedValue;
45
+
46
+ $allModules.each(function () {
47
+ const settings = $.isPlainObject(parameters)
48
+ ? $.extend(true, {}, $.fn.slider.settings, parameters)
49
+ : $.extend({}, $.fn.slider.settings);
50
+
51
+ const className = settings.className;
52
+ const metadata = settings.metadata;
53
+ const namespace = settings.namespace;
54
+ const error = settings.error;
55
+ const keys = settings.keys;
56
+ const interpretLabel = settings.interpretLabel;
57
+
58
+ let isHover = false;
59
+ const eventNamespace = '.' + namespace;
60
+ const moduleNamespace = 'module-' + namespace;
61
+
62
+ const $module = $(this);
63
+ let $currThumb;
64
+ let touchIdentifier;
65
+ let $thumb;
66
+ let $secondThumb;
67
+ let $track;
68
+ let $trackFill;
69
+ let $labels;
70
+
71
+ const element = this;
72
+ let instance = $module.data(moduleNamespace);
73
+
74
+ let documentEventID;
75
+
76
+ let value;
77
+ let position;
78
+ let secondPos;
79
+ let offset;
80
+ let gapRatio = 1;
81
+ let previousValue;
82
+
83
+ let initialPosition;
84
+ let initialLoad;
85
+
86
+ const module = {
87
+
88
+ initialize: function () {
89
+ module.debug('Initializing slider', settings);
90
+ initialLoad = true;
91
+
92
+ currentRange += 1;
93
+ documentEventID = currentRange;
94
+
95
+ module.setup.layout();
96
+ module.setup.labels();
97
+
98
+ module.bind.events();
99
+
100
+ module.read.metadata();
101
+ module.read.settings();
102
+
103
+ initialLoad = false;
104
+ module.instantiate();
105
+ },
106
+
107
+ instantiate: function () {
108
+ module.verbose('Storing instance of slider', module);
109
+ instance = module;
110
+ $module
111
+ .data(moduleNamespace, module);
112
+ },
113
+
114
+ destroy: function () {
115
+ module.verbose('Destroying previous slider for', $module);
116
+ clearInterval(instance.interval);
117
+ module.unbind.events();
118
+ module.unbind.slidingEvents();
119
+ delete module.cache;
120
+ $module.removeData(moduleNamespace);
121
+ instance = undefined;
122
+ },
123
+
124
+ setup: {
125
+ layout: function () {
126
+ if ($module.attr('tabindex') === undefined) {
127
+ $module.attr('tabindex', 0);
128
+ }
129
+ if ($module.find('.inner').length === 0) {
130
+ $module.append('<div class="inner">'
131
+ + '<div class="track"></div>'
132
+ + '<div class="track-fill"></div>'
133
+ + '<div class="thumb"></div>'
134
+ + '</div>');
135
+ }
136
+ module.clear.cache();
137
+ $thumb = $module.find('.thumb:not(.second)');
138
+ if (settings.showThumbTooltip) {
139
+ $thumb
140
+ .attr('data-position', settings.tooltipConfig.position)
141
+ .attr('data-variation', settings.tooltipConfig.variation);
142
+ }
143
+ $currThumb = $thumb;
144
+ if (module.is.range()) {
145
+ if ($module.find('.thumb.second').length === 0) {
146
+ $module.find('.inner').append('<div class="thumb second"></div>');
147
+ }
148
+ $secondThumb = $module.find('.thumb.second');
149
+ if (settings.showThumbTooltip) {
150
+ $secondThumb
151
+ .attr('data-position', settings.tooltipConfig.position)
152
+ .attr('data-variation', settings.tooltipConfig.variation);
153
+ }
154
+ }
155
+ $track = $module.find('.track');
156
+ $trackFill = $module.find('.track-fill');
157
+ offset = $thumb.width() / 2;
158
+ },
159
+ labels: function () {
160
+ if (module.is.labeled()) {
161
+ $labels = $module.find('.labels:not(.auto)');
162
+ if ($labels.length > 0) {
163
+ module.setup.customLabel();
164
+ } else {
165
+ module.setup.autoLabel();
166
+ }
167
+
168
+ if (settings.highlightRange) {
169
+ $labels.addClass(className.active);
170
+ }
171
+
172
+ if (settings.showLabelTicks) {
173
+ $module.addClass(className.ticked);
174
+ } else if ($module.hasClass(className.ticked)) {
175
+ settings.showLabelTicks = 'always';
176
+ }
177
+ }
178
+ },
179
+ customLabel: function () {
180
+ const $children = $labels.find('.label');
181
+ const numChildren = $children.length;
182
+ const min = module.get.min();
183
+ const max = module.get.max();
184
+ let ratio;
185
+ $children.each(function (index) {
186
+ const $child = $(this);
187
+ let attrValue = $child.attr('data-value');
188
+ if (attrValue) {
189
+ attrValue = attrValue > max
190
+ ? max
191
+ : Math.max(attrValue, min);
192
+ ratio = (attrValue - min) / (max - min);
193
+ } else {
194
+ ratio = (index + 1) / (numChildren + 1);
195
+ }
196
+ module.update.labelPosition(ratio, $(this));
197
+ });
198
+ },
199
+ autoLabel: function () {
200
+ $labels = $module.find('.labels');
201
+ if ($labels.length > 0) {
202
+ $labels.empty();
203
+ } else {
204
+ $labels = $module.append('<ul class="auto labels"></ul>').find('.labels');
205
+ }
206
+ const step = module.get.step();
207
+ const precision = module.get.precision();
208
+ const len = module.get.numLabels();
209
+ const ignoreLabels = len - (settings.autoAdjustLabels !== 'fixed' ? 0 : module.get.max().toString().length + 4);
210
+ for (let i = 0; i <= len; i++) {
211
+ const stepValue = Math.round(((i * (step === 0 ? 1 : step)) + module.get.min()) * precision) / precision;
212
+ const labelText = module.get.label(i, stepValue);
213
+ const showLabel = settings.restrictedLabels.length === 0 || settings.restrictedLabels.includes(labelText);
214
+ const $label = labelText !== '' && (showLabel || settings.showLabelTicks === 'always')
215
+ ? ((!(i % module.get.gapRatio()) && i < ignoreLabels) || i === len
216
+ ? $('<li/>', { class: className.label, 'data-value': stepValue, html: showLabel ? labelText : '' })
217
+ : $('<li/>', { class: 'halftick label', 'data-value': stepValue }))
218
+ : null;
219
+ const ratio = i / len;
220
+ if ($label) {
221
+ module.update.labelPosition(ratio, $label);
222
+ $labels.append($label);
223
+ }
224
+ }
225
+ },
226
+ },
227
+
228
+ bind: {
229
+ events: function () {
230
+ module.bind.globalKeyboardEvents();
231
+ module.bind.keyboardEvents();
232
+ module.bind.mouseEvents();
233
+ if (settings.autoAdjustLabels) {
234
+ module.bind.windowEvents();
235
+ }
236
+ },
237
+ keyboardEvents: function () {
238
+ module.verbose('Binding keyboard events');
239
+ $module.on('keydown' + eventNamespace, module.event.keydown);
240
+ },
241
+ globalKeyboardEvents: function () {
242
+ $document.on('keydown' + eventNamespace + documentEventID, module.event.activateFocus);
243
+ },
244
+ mouseEvents: function () {
245
+ module.verbose('Binding mouse and touch events');
246
+ $module.find('.track, .thumb, .inner').on('mousedown' + eventNamespace, function (event) {
247
+ event.stopImmediatePropagation();
248
+ event.preventDefault();
249
+ module.event.down(event);
250
+ });
251
+ $module.on('mousedown' + eventNamespace, module.event.down);
252
+ $module.on('mouseenter' + eventNamespace, function (event) {
253
+ isHover = true;
254
+ });
255
+ $module.on('mouseleave' + eventNamespace, function (event) {
256
+ isHover = false;
257
+ });
258
+ // All touch events are invoked on the element where the touch *started*. Thus, we can bind them all
259
+ // on the thumb(s) and don't need to worry about interference with other components, i.e., no dynamic binding
260
+ // and unbinding required.
261
+ $module.find('.thumb')
262
+ .on('touchstart' + eventNamespace, module.event.touchDown)
263
+ .on('touchmove' + eventNamespace, module.event.move)
264
+ .on('touchend' + eventNamespace, module.event.up)
265
+ .on('touchcancel' + eventNamespace, module.event.touchCancel);
266
+ },
267
+ slidingEvents: function () {
268
+ // these don't need the identifier because we only ever want one of them to be registered with the document
269
+ module.verbose('Binding page wide events while handle is being draged');
270
+ $document.on('mousemove' + eventNamespace, module.event.move);
271
+ $document.on('mouseup' + eventNamespace, module.event.up);
272
+ },
273
+ windowEvents: function () {
274
+ $window.on('resize' + eventNamespace, module.event.resize);
275
+ },
276
+ },
277
+
278
+ unbind: {
279
+ events: function () {
280
+ $module.find('.track, .thumb, .inner').off('mousedown' + eventNamespace);
281
+ $module.off('mousedown' + eventNamespace);
282
+ $module.off('mouseenter' + eventNamespace);
283
+ $module.off('mouseleave' + eventNamespace);
284
+ $module.find('.thumb')
285
+ .off('touchstart' + eventNamespace)
286
+ .off('touchmove' + eventNamespace)
287
+ .off('touchend' + eventNamespace)
288
+ .off('touchcancel' + eventNamespace);
289
+ $module.off('keydown' + eventNamespace);
290
+ $module.off('focusout' + eventNamespace);
291
+ $document.off('keydown' + eventNamespace + documentEventID, module.event.activateFocus);
292
+ $window.off('resize' + eventNamespace);
293
+ },
294
+ slidingEvents: function () {
295
+ $document.off('mousemove' + eventNamespace);
296
+ $document.off('mouseup' + eventNamespace);
297
+ },
298
+ },
299
+
300
+ event: {
301
+ down: function (event) {
302
+ event.preventDefault();
303
+ if (module.is.range()) {
304
+ const eventPos = module.determine.eventPos(event);
305
+ const newPos = module.determine.pos(eventPos);
306
+ // Special handling if range mode and both thumbs have the same value
307
+ if (settings.preventCrossover && module.is.range() && module.thumbVal === module.secondThumbVal) {
308
+ initialPosition = newPos;
309
+ $currThumb = undefined;
310
+ } else {
311
+ $currThumb = module.determine.closestThumb(newPos);
312
+ }
313
+ if (previousValue === undefined) {
314
+ previousValue = module.get.currentThumbValue();
315
+ }
316
+ } else if (previousValue === undefined) {
317
+ previousValue = module.get.value();
318
+ }
319
+
320
+ if (!module.is.disabled()) {
321
+ module.bind.slidingEvents();
322
+ }
323
+ },
324
+ touchDown: function (event) {
325
+ event.preventDefault(); // disable mouse emulation and touch-scrolling
326
+ event.stopImmediatePropagation();
327
+ if (touchIdentifier !== undefined) {
328
+ // ignore multiple touches on the same slider --
329
+ // we cannot handle changing both thumbs at once due to shared state
330
+ return;
331
+ }
332
+ $currThumb = $(event.target);
333
+ const touchEvent = event.touches ? event : event.originalEvent;
334
+ touchIdentifier = touchEvent.targetTouches[0].identifier;
335
+ if (previousValue === undefined) {
336
+ previousValue = module.get.currentThumbValue();
337
+ }
338
+ },
339
+ move: function (event) {
340
+ if (event.type === 'mousemove') {
341
+ event.preventDefault(); // prevent text selection etc.
342
+ }
343
+ if (module.is.disabled()) {
344
+ // touch events are always bound, so we need to prevent touch-sliding on disabled sliders here
345
+ return;
346
+ }
347
+ let value = module.determine.valueFromEvent(event);
348
+ if (event.type === 'mousemove' && $currThumb === undefined) {
349
+ const eventPos = module.determine.eventPos(event);
350
+ const newPos = module.determine.pos(eventPos);
351
+ $currThumb = initialPosition > newPos ? $thumb : $secondThumb;
352
+ }
353
+ if (module.is.range() && (settings.minRange || settings.maxRange)) {
354
+ const currentRangeDiff = module.get.currentRangeDiff(value);
355
+ const isSecondThumb = $currThumb.hasClass('second');
356
+ if ((settings.minRange && currentRangeDiff < settings.minRange)
357
+ || (settings.maxRange && currentRangeDiff > settings.maxRange)
358
+ || (settings.preventCrossover && !isSecondThumb && value > module.secondThumbVal)
359
+ || (settings.preventCrossover && isSecondThumb && value < module.thumbVal)
360
+ ) {
361
+ return;
362
+ }
363
+ }
364
+ if (module.get.step() === 0 || module.is.smooth()) {
365
+ let thumbVal = module.thumbVal;
366
+ let secondThumbVal = module.secondThumbVal;
367
+ let thumbSmoothVal = module.determine.smoothValueFromEvent(event);
368
+ if (!$currThumb.hasClass('second')) {
369
+ if (settings.preventCrossover && module.is.range()) {
370
+ value = Math.min(secondThumbVal, value);
371
+ thumbSmoothVal = Math.min(secondThumbVal, thumbSmoothVal);
372
+ }
373
+ thumbVal = value;
374
+ } else {
375
+ if (settings.preventCrossover && module.is.range()) {
376
+ value = Math.max(thumbVal, value);
377
+ thumbSmoothVal = Math.max(thumbVal, thumbSmoothVal);
378
+ }
379
+ secondThumbVal = value;
380
+ }
381
+ value = Math.abs(thumbVal - (secondThumbVal || 0));
382
+ module.update.position(thumbSmoothVal);
383
+ settings.onMove.call(element, value, thumbVal, secondThumbVal);
384
+ } else {
385
+ module.update.value(value, function (value, thumbVal, secondThumbVal) {
386
+ settings.onMove.call(element, value, thumbVal, secondThumbVal);
387
+ });
388
+ }
389
+ },
390
+ up: function (event) {
391
+ event.preventDefault();
392
+ if (module.is.disabled()) {
393
+ // touch events are always bound, so we need to prevent touch-sliding on disabled sliders here
394
+ return;
395
+ }
396
+ let value = module.determine.valueFromEvent(event);
397
+ if (module.is.range() && (settings.minRange || settings.maxRange)) {
398
+ if ($currThumb === undefined) {
399
+ $currThumb = value <= module.get.currentThumbValue() ? $thumb : $secondThumb;
400
+ }
401
+ const currentRangeDiff = module.get.currentRangeDiff(value);
402
+ if (settings.minRange && currentRangeDiff < settings.minRange) {
403
+ value = module.get.edgeValue(value, settings.minRange);
404
+ } else if (settings.maxRange && currentRangeDiff > settings.maxRange) {
405
+ value = module.get.edgeValue(value, settings.maxRange);
406
+ }
407
+ }
408
+ module.set.value(value);
409
+ module.unbind.slidingEvents();
410
+ touchIdentifier = undefined;
411
+ if (previousValue !== undefined) {
412
+ previousValue = undefined;
413
+ }
414
+ },
415
+ touchCancel: function (event) {
416
+ event.preventDefault();
417
+ touchIdentifier = undefined;
418
+ if (previousValue !== undefined) {
419
+ module.update.value(previousValue);
420
+ previousValue = undefined;
421
+ }
422
+ },
423
+ keydown: function (event, first) {
424
+ if (module.is.disabled()) {
425
+ return;
426
+ }
427
+ if (settings.preventCrossover && module.is.range() && module.thumbVal === module.secondThumbVal) {
428
+ $currThumb = undefined;
429
+ }
430
+ if (module.is.focused()) {
431
+ $document.trigger(event);
432
+ }
433
+ if (first || module.is.focused()) {
434
+ const step = module.determine.keyMovement(event);
435
+ if (step !== NO_STEP) {
436
+ event.preventDefault();
437
+ switch (step) {
438
+ case SINGLE_STEP: {
439
+ module.takeStep();
440
+
441
+ break;
442
+ }
443
+ case BIG_STEP: {
444
+ module.takeStep(module.get.multiplier());
445
+
446
+ break;
447
+ }
448
+ case SINGLE_BACKSTEP: {
449
+ module.backStep();
450
+
451
+ break;
452
+ }
453
+ case BIG_BACKSTEP: {
454
+ module.backStep(module.get.multiplier());
455
+
456
+ break;
457
+ }
458
+ // no default
459
+ }
460
+ }
461
+ }
462
+ },
463
+ activateFocus: function (event) {
464
+ if (!module.is.disabled() && !module.is.focused() && module.is.hover() && module.determine.keyMovement(event) !== NO_STEP) {
465
+ event.preventDefault();
466
+ module.event.keydown(event, true);
467
+ $module.trigger('focus');
468
+ }
469
+ },
470
+ resize: function (_event) {
471
+ // To avoid a useless performance cost, we only call the label refresh when its necessary
472
+ if (gapRatio !== module.get.gapRatio()) {
473
+ module.resync();
474
+ gapRatio = module.get.gapRatio();
475
+ }
476
+ },
477
+ },
478
+
479
+ clear: {
480
+ cache: function () {
481
+ module.cache = {};
482
+ },
483
+ },
484
+
485
+ resync: function () {
486
+ module.verbose('Re-syncing thumb position based on value');
487
+ module.setup.labels();
488
+ if (module.is.range()) {
489
+ module.update.position(module.secondThumbVal, $secondThumb);
490
+ }
491
+ module.update.position(module.thumbVal, $thumb);
492
+ },
493
+ takeStep: function (multiplier) {
494
+ if (!multiplier) {
495
+ multiplier = 1;
496
+ }
497
+ const step = module.get.step();
498
+ const currValue = module.get.currentThumbValue();
499
+ module.verbose('Taking a step');
500
+ if (step > 0) {
501
+ module.set.value(currValue + step * multiplier);
502
+ } else if (step === 0) {
503
+ const precision = module.get.precision();
504
+ const newValue = currValue + (multiplier / precision);
505
+ module.set.value(Math.round(newValue * precision) / precision);
506
+ }
507
+ },
508
+
509
+ backStep: function (multiplier) {
510
+ if (!multiplier) {
511
+ multiplier = 1;
512
+ }
513
+ const step = module.get.step();
514
+ const currValue = module.get.currentThumbValue();
515
+ module.verbose('Going back a step');
516
+ if (step > 0) {
517
+ module.set.value(currValue - step * multiplier);
518
+ } else if (step === 0) {
519
+ const precision = module.get.precision();
520
+ const newValue = currValue - (multiplier / precision);
521
+ module.set.value(Math.round(newValue * precision) / precision);
522
+ }
523
+ },
524
+
525
+ is: {
526
+ prime: function (n) {
527
+ if (module.cache['prime' + n] === undefined) {
528
+ let p = true;
529
+ for (let i = 2, s = Math.sqrt(n); i <= s; i++) {
530
+ if (n % i === 0) {
531
+ p = false;
532
+
533
+ break;
534
+ }
535
+ }
536
+ if (p) {
537
+ p = n > 1;
538
+ }
539
+
540
+ module.cache['prime' + n] = p;
541
+ }
542
+
543
+ return module.cache['prime' + n];
544
+ },
545
+ range: function () {
546
+ let isRange = $module.hasClass(className.range);
547
+ if (!isRange && (settings.minRange || settings.maxRange)) {
548
+ $module.addClass(className.range);
549
+ isRange = true;
550
+ }
551
+
552
+ return isRange;
553
+ },
554
+ hover: function () {
555
+ return isHover;
556
+ },
557
+ focused: function () {
558
+ return $module.is(':focus');
559
+ },
560
+ disabled: function () {
561
+ return $module.hasClass(className.disabled);
562
+ },
563
+ labeled: function () {
564
+ let isLabeled = $module.hasClass(className.labeled);
565
+ if (!isLabeled && (settings.restrictedLabels.length > 0 || settings.showLabelTicks !== false)) {
566
+ $module.addClass(className.labeled);
567
+ isLabeled = true;
568
+ }
569
+
570
+ return isLabeled;
571
+ },
572
+ reversed: function () {
573
+ return $module.hasClass(className.reversed);
574
+ },
575
+ vertical: function () {
576
+ return $module.hasClass(className.vertical);
577
+ },
578
+ smooth: function () {
579
+ return settings.smooth || $module.hasClass(className.smooth);
580
+ },
581
+ },
582
+
583
+ get: {
584
+ currentRangeDiff: function (value) {
585
+ let currentRangeDiff;
586
+ if ($currThumb.hasClass('second')) {
587
+ currentRangeDiff = module.thumbVal < value
588
+ ? value - module.thumbVal
589
+ : module.thumbVal - value;
590
+ } else {
591
+ currentRangeDiff = module.secondThumbVal > value
592
+ ? module.secondThumbVal - value
593
+ : value - module.secondThumbVal;
594
+ }
595
+
596
+ return currentRangeDiff;
597
+ },
598
+ edgeValue: function (value, edgeValue) {
599
+ if ($currThumb.hasClass('second')) {
600
+ value = module.thumbVal < value
601
+ ? module.thumbVal + edgeValue
602
+ : module.thumbVal - edgeValue;
603
+ } else {
604
+ value = module.secondThumbVal < value
605
+ ? module.secondThumbVal + edgeValue
606
+ : module.secondThumbVal - edgeValue;
607
+ }
608
+
609
+ return value;
610
+ },
611
+ trackOffset: function () {
612
+ if (module.is.vertical()) {
613
+ return $track.offset().top;
614
+ }
615
+
616
+ return $track.offset().left;
617
+ },
618
+ trackLength: function () {
619
+ if (module.is.vertical()) {
620
+ return $track.height();
621
+ }
622
+
623
+ return $track.width();
624
+ },
625
+ trackLeft: function () {
626
+ if (module.is.vertical()) {
627
+ return $track.position().top;
628
+ }
629
+
630
+ return $track.position().left;
631
+ },
632
+ trackStartPos: function () {
633
+ return module.is.reversed() ? module.get.trackLeft() + module.get.trackLength() : module.get.trackLeft();
634
+ },
635
+ trackEndPos: function () {
636
+ return module.is.reversed() ? module.get.trackLeft() : module.get.trackLeft() + module.get.trackLength();
637
+ },
638
+ trackStartMargin: function () {
639
+ let margin;
640
+ if (module.is.vertical()) {
641
+ margin = module.is.reversed() ? $module.css('padding-bottom') : $module.css('padding-top');
642
+ } else {
643
+ margin = module.is.reversed() ? $module.css('padding-right') : $module.css('padding-left');
644
+ }
645
+
646
+ return margin || '0px';
647
+ },
648
+ trackEndMargin: function () {
649
+ let margin;
650
+ if (module.is.vertical()) {
651
+ margin = module.is.reversed() ? $module.css('padding-top') : $module.css('padding-bottom');
652
+ } else {
653
+ margin = module.is.reversed() ? $module.css('padding-left') : $module.css('padding-right');
654
+ }
655
+
656
+ return margin || '0px';
657
+ },
658
+ precision: function () {
659
+ if (module.cache.precision === undefined) {
660
+ let decimalPlaces;
661
+ const step = module.get.step();
662
+ if (step !== 0) {
663
+ const split = String(step).split('.');
664
+ decimalPlaces = split.length === 2 ? split[1].length : 0;
665
+ } else {
666
+ decimalPlaces = settings.decimalPlaces;
667
+ }
668
+ const precision = 10 ** decimalPlaces;
669
+ module.debug('Precision determined', precision);
670
+ module.cache.precision = precision;
671
+ }
672
+
673
+ return module.cache.precision;
674
+ },
675
+ min: function () {
676
+ return settings.min;
677
+ },
678
+ max: function () {
679
+ if (module.cache.max === undefined) {
680
+ const step = module.get.step();
681
+ const min = module.get.min();
682
+ const precision = module.get.precision();
683
+ const quotient = step === 0 ? 0 : Math.floor(Math.round(((settings.max - min) / step) * precision) / precision);
684
+ const remainder = step === 0 ? 0 : (settings.max - min) % step;
685
+ if (remainder > 0) {
686
+ module.debug('Max value not divisible by given step. Increasing max value.', settings.max, step);
687
+ }
688
+ module.cache.max = remainder === 0 ? settings.max : min + quotient * step;
689
+ }
690
+
691
+ return module.cache.max;
692
+ },
693
+ step: function () {
694
+ return settings.step;
695
+ },
696
+ numLabels: function () {
697
+ if (module.cache.numLabels === undefined) {
698
+ const step = module.get.step();
699
+ const precision = module.get.precision();
700
+ const value = Math.round(((module.get.max() - module.get.min()) / (step === 0 ? 1 : step)) * precision) / precision;
701
+ module.debug('Determined that there should be ' + value + ' labels');
702
+ module.cache.numLabels = value;
703
+ }
704
+
705
+ return module.cache.numLabels;
706
+ },
707
+ labelType: function () {
708
+ return settings.labelType;
709
+ },
710
+ label: function (value, stepValue) {
711
+ if (isFunction(interpretLabel)) {
712
+ return interpretLabel(value, stepValue, module);
713
+ }
714
+
715
+ switch (settings.labelType) {
716
+ case settings.labelTypes.number: {
717
+ return stepValue;
718
+ }
719
+ case settings.labelTypes.letter: {
720
+ if (value < 0 || module.get.precision() > 1) {
721
+ module.error(error.invalidLetterNumber, value);
722
+
723
+ return value;
724
+ }
725
+ let letterLabel = '';
726
+ const letters = Array.isArray(settings.letters) ? settings.letters : [...String(settings.letters)];
727
+ const lettersLen = letters.length;
728
+
729
+ while (stepValue >= 0) {
730
+ letterLabel = letters[stepValue % lettersLen] + letterLabel;
731
+ stepValue = Math.floor(stepValue / lettersLen) - 1;
732
+ }
733
+
734
+ return letterLabel;
735
+ }
736
+ default: {
737
+ return value;
738
+ }
739
+ }
740
+ },
741
+ value: function () {
742
+ return value;
743
+ },
744
+ settings: function () {
745
+ return settings;
746
+ },
747
+ currentThumbValue: function () {
748
+ return $currThumb !== undefined && $currThumb.hasClass('second') ? module.secondThumbVal : module.thumbVal;
749
+ },
750
+ thumbValue: function (which) {
751
+ switch (which) {
752
+ case 'second': {
753
+ if (module.is.range()) {
754
+ return module.secondThumbVal;
755
+ }
756
+
757
+ module.error(error.notrange);
758
+
759
+ break;
760
+ }
761
+ default: {
762
+ return module.thumbVal;
763
+ }
764
+ }
765
+ },
766
+ multiplier: function () {
767
+ return settings.pageMultiplier;
768
+ },
769
+ thumbPosition: function (which) {
770
+ switch (which) {
771
+ case 'second': {
772
+ if (module.is.range()) {
773
+ return secondPos;
774
+ }
775
+
776
+ module.error(error.notrange);
777
+
778
+ break;
779
+ }
780
+ default: {
781
+ return position;
782
+ }
783
+ }
784
+ },
785
+ gapRatio: function () {
786
+ let gapRatio = 1;
787
+
788
+ if (settings.autoAdjustLabels) {
789
+ const numLabels = module.get.numLabels();
790
+ const primePlus = module.is.prime(numLabels) ? 1 : 0;
791
+ const trackLength = module.get.trackLength();
792
+ let gapCounter = 1;
793
+
794
+ // While the distance between two labels is too short,
795
+ // we divide the number of labels at each iteration
796
+ // and apply only if the modulo of the operation is an odd number.
797
+ if (trackLength > 0) {
798
+ while ((trackLength / numLabels) * gapCounter < settings.labelDistance) {
799
+ if (!((numLabels + primePlus) % gapCounter) || settings.autoAdjustLabels === 'fixed') {
800
+ gapRatio = gapCounter;
801
+ }
802
+ gapCounter += 1;
803
+ }
804
+ }
805
+ }
806
+
807
+ return gapRatio;
808
+ },
809
+ },
810
+
811
+ determine: {
812
+ pos: function (pagePos) {
813
+ return module.is.reversed()
814
+ ? module.get.trackStartPos() - pagePos + module.get.trackOffset()
815
+ : pagePos - module.get.trackOffset() - module.get.trackStartPos();
816
+ },
817
+ closestThumb: function (eventPos) {
818
+ const thumbPos = Number.parseFloat(module.determine.thumbPos($thumb));
819
+ const thumbDelta = Math.abs(eventPos - thumbPos);
820
+ const secondThumbPos = Number.parseFloat(module.determine.thumbPos($secondThumb));
821
+ const secondThumbDelta = Math.abs(eventPos - secondThumbPos);
822
+ if (thumbDelta === secondThumbDelta && module.get.thumbValue() === module.get.min()) {
823
+ return $secondThumb;
824
+ }
825
+
826
+ return thumbDelta <= secondThumbDelta ? $thumb : $secondThumb;
827
+ },
828
+ closestThumbPos: function (eventPos) {
829
+ const thumbPos = Number.parseFloat(module.determine.thumbPos($thumb));
830
+ const thumbDelta = Math.abs(eventPos - thumbPos);
831
+ const secondThumbPos = Number.parseFloat(module.determine.thumbPos($secondThumb));
832
+ const secondThumbDelta = Math.abs(eventPos - secondThumbPos);
833
+
834
+ return thumbDelta <= secondThumbDelta ? thumbPos : secondThumbPos;
835
+ },
836
+ thumbPos: function ($element) {
837
+ return module.is.vertical()
838
+ ? (module.is.reversed() ? $element.css('bottom') : $element.css('top'))
839
+ : (module.is.reversed() ? $element.css('right') : $element.css('left'));
840
+ },
841
+ positionFromValue: function (val) {
842
+ const min = module.get.min();
843
+ const max = module.get.max();
844
+ const value = val > max
845
+ ? max
846
+ : Math.max(val, min);
847
+ const trackLength = module.get.trackLength();
848
+ const ratio = (value - min) / (max - min);
849
+ const position = Math.round(ratio * trackLength);
850
+ module.verbose('Determined position: ' + position + ' from value: ' + value);
851
+
852
+ return position;
853
+ },
854
+ positionFromRatio: function (ratio) {
855
+ const trackLength = module.get.trackLength();
856
+ const step = module.get.step();
857
+ const position = Math.round(ratio * trackLength);
858
+ const adjustedPos = step === 0 ? position : Math.round(position / step) * step;
859
+ module.verbose('Determined position: ' + position + ' from ratio: ' + ratio);
860
+
861
+ return adjustedPos;
862
+ },
863
+ valueFromEvent: function (event) {
864
+ const eventPos = module.determine.eventPos(event);
865
+ const newPos = module.determine.pos(eventPos);
866
+ let value;
867
+ if (eventPos < module.get.trackOffset()) {
868
+ value = module.is.reversed() ? module.get.max() : module.get.min();
869
+ } else if (eventPos > module.get.trackOffset() + module.get.trackLength()) {
870
+ value = module.is.reversed() ? module.get.min() : module.get.max();
871
+ } else {
872
+ value = module.determine.value(newPos);
873
+ }
874
+
875
+ return value;
876
+ },
877
+ smoothValueFromEvent: function (event) {
878
+ const min = module.get.min();
879
+ const max = module.get.max();
880
+ const trackLength = module.get.trackLength();
881
+ const eventPos = module.determine.eventPos(event);
882
+ let newPos = eventPos - module.get.trackOffset();
883
+ let ratio;
884
+ newPos = newPos < 0
885
+ ? 0
886
+ : Math.min(newPos, trackLength);
887
+ ratio = newPos / trackLength;
888
+ if (module.is.reversed()) {
889
+ ratio = 1 - ratio;
890
+ }
891
+
892
+ return ratio * (max - min) + min;
893
+ },
894
+ eventPos: function (event) {
895
+ if (event.type === 'touchmove' || event.type === 'touchend') {
896
+ const touchEvent = event.touches ? event : event.originalEvent;
897
+ let touch = touchEvent.changedTouches[0]; // fall back to first touch if correct touch not found
898
+ for (const t of touchEvent.touches) {
899
+ if (t.identifier === touchIdentifier) {
900
+ touch = t;
901
+
902
+ break;
903
+ }
904
+ }
905
+ const touchY = touch.pageY;
906
+ const touchX = touch.pageX;
907
+
908
+ return module.is.vertical() ? touchY : touchX;
909
+ }
910
+ const clickY = event.pageY || event.originalEvent.pageY;
911
+ const clickX = event.pageX || event.originalEvent.pageX;
912
+
913
+ return module.is.vertical() ? clickY : clickX;
914
+ },
915
+ value: function (position) {
916
+ const precision = module.get.precision();
917
+ const startPos = module.is.reversed() ? module.get.trackEndPos() : module.get.trackStartPos();
918
+ const endPos = module.is.reversed() ? module.get.trackStartPos() : module.get.trackEndPos();
919
+ const ratio = (position - startPos) / (endPos - startPos);
920
+ const range = module.get.max() - module.get.min();
921
+ const step = module.get.step();
922
+ const value = ratio * range;
923
+ const difference = step === 0 ? value : Math.round(value / step) * step;
924
+ module.verbose('Determined value based upon position: ' + position + ' as: ' + value);
925
+ if (value !== difference) {
926
+ module.verbose('Rounding value to closest step: ' + difference);
927
+ }
928
+ // Use precision to avoid ugly JavaScript floating point rounding issues
929
+ // (like 35 * .01 = 0.35000000000000003)
930
+ module.verbose('Cutting off additional decimal places');
931
+
932
+ return Math.round((difference + module.get.min()) * precision) / precision;
933
+ },
934
+ keyMovement: function (event) {
935
+ const key = event.which;
936
+ const downArrow = module.is.vertical()
937
+ ? (module.is.reversed() ? keys.downArrow : keys.upArrow)
938
+ : keys.downArrow;
939
+ const upArrow = module.is.vertical()
940
+ ? (module.is.reversed() ? keys.upArrow : keys.downArrow)
941
+ : keys.upArrow;
942
+ const leftArrow = !module.is.vertical()
943
+ ? (module.is.reversed() ? keys.rightArrow : keys.leftArrow)
944
+ : keys.leftArrow;
945
+ const rightArrow = !module.is.vertical()
946
+ ? (module.is.reversed() ? keys.leftArrow : keys.rightArrow)
947
+ : keys.rightArrow;
948
+ if (key === downArrow || key === leftArrow) {
949
+ return SINGLE_BACKSTEP;
950
+ }
951
+ if (key === upArrow || key === rightArrow) {
952
+ return SINGLE_STEP;
953
+ }
954
+ if (key === keys.pageDown) {
955
+ return BIG_BACKSTEP;
956
+ }
957
+ if (key === keys.pageUp) {
958
+ return BIG_STEP;
959
+ }
960
+
961
+ return NO_STEP;
962
+ },
963
+ },
964
+
965
+ handleNewValuePosition: function (val) {
966
+ const min = module.get.min();
967
+ const max = module.get.max();
968
+ if (val <= min) {
969
+ val = min;
970
+ } else if (val >= max) {
971
+ val = max;
972
+ }
973
+
974
+ return module.determine.positionFromValue(val);
975
+ },
976
+
977
+ set: {
978
+ active: function (thumbVal, secondThumbVal) {
979
+ if (settings.highlightRange) {
980
+ if (secondThumbVal < thumbVal) {
981
+ const tempVal = secondThumbVal;
982
+ secondThumbVal = thumbVal;
983
+ thumbVal = tempVal;
984
+ }
985
+ const $children = $labels.find('.label');
986
+ $children.each(function (index) {
987
+ const $child = $(this);
988
+ let attrValue = $child.attr('data-value');
989
+ if (attrValue) {
990
+ attrValue = Number.parseInt(attrValue, 10);
991
+ if (attrValue >= thumbVal && attrValue <= secondThumbVal) {
992
+ $child.addClass(className.active);
993
+ } else {
994
+ $child.removeClass(className.active);
995
+ }
996
+ }
997
+ });
998
+ }
999
+ },
1000
+ value: function (newValue, fireChange) {
1001
+ fireChange = fireChange !== false;
1002
+ const toReset = previousValue === undefined;
1003
+ previousValue = previousValue === undefined ? module.get.value() : previousValue;
1004
+ module.update.value(newValue, function (value, thumbVal, secondThumbVal) {
1005
+ if ((!initialLoad || settings.fireOnInit) && fireChange) {
1006
+ if (newValue !== previousValue) {
1007
+ settings.onChange.call(element, value, thumbVal, secondThumbVal);
1008
+ }
1009
+ settings.onMove.call(element, value, thumbVal, secondThumbVal);
1010
+ }
1011
+ if (toReset) {
1012
+ previousValue = undefined;
1013
+ }
1014
+ });
1015
+ },
1016
+ rangeValue: function (first, second, fireChange) {
1017
+ fireChange = fireChange !== false;
1018
+ if (module.is.range()) {
1019
+ const min = module.get.min();
1020
+ const max = module.get.max();
1021
+ const toReset = previousValue === undefined;
1022
+ previousValue = previousValue === undefined ? module.get.value() : previousValue;
1023
+ if (first <= min) {
1024
+ first = min;
1025
+ } else if (first >= max) {
1026
+ first = max;
1027
+ }
1028
+ if (second <= min) {
1029
+ second = min;
1030
+ } else if (second >= max) {
1031
+ second = max;
1032
+ }
1033
+ module.thumbVal = first;
1034
+ module.secondThumbVal = second;
1035
+ value = Math.abs(module.thumbVal - module.secondThumbVal);
1036
+ module.update.position(module.thumbVal, $thumb);
1037
+ module.update.position(module.secondThumbVal, $secondThumb);
1038
+ if ((!initialLoad || settings.fireOnInit) && fireChange) {
1039
+ if (value !== previousValue) {
1040
+ settings.onChange.call(element, value, module.thumbVal, module.secondThumbVal);
1041
+ }
1042
+ settings.onMove.call(element, value, module.thumbVal, module.secondThumbVal);
1043
+ }
1044
+ if (toReset) {
1045
+ previousValue = undefined;
1046
+ }
1047
+ } else {
1048
+ module.error(error.notrange);
1049
+ }
1050
+ },
1051
+ position: function (position, which) {
1052
+ const thumbVal = module.determine.value(position);
1053
+ if (which === 'second') {
1054
+ module.secondThumbVal = thumbVal;
1055
+ module.update.position(thumbVal, $secondThumb);
1056
+ } else {
1057
+ module.thumbVal = thumbVal;
1058
+ module.update.position(thumbVal, $thumb);
1059
+ }
1060
+ value = Math.abs(module.thumbVal - (module.secondThumbVal || 0));
1061
+ module.set.value(value);
1062
+ },
1063
+ },
1064
+
1065
+ update: {
1066
+ value: function (newValue, callback) {
1067
+ const min = module.get.min();
1068
+ const max = module.get.max();
1069
+ if (newValue <= min) {
1070
+ newValue = min;
1071
+ } else if (newValue >= max) {
1072
+ newValue = max;
1073
+ }
1074
+ if (!module.is.range()) {
1075
+ value = newValue;
1076
+ module.thumbVal = value;
1077
+ } else {
1078
+ if ($currThumb === undefined) {
1079
+ $currThumb = newValue <= module.get.currentThumbValue() ? $thumb : $secondThumb;
1080
+ }
1081
+ if (!$currThumb.hasClass('second')) {
1082
+ if (settings.preventCrossover && module.is.range()) {
1083
+ newValue = Math.min(module.secondThumbVal - (settings.minRange || 0), newValue);
1084
+ }
1085
+ module.thumbVal = newValue;
1086
+ } else {
1087
+ if (settings.preventCrossover && module.is.range()) {
1088
+ newValue = Math.max(module.thumbVal + (settings.minRange || 0), newValue);
1089
+ }
1090
+ module.secondThumbVal = newValue;
1091
+ }
1092
+ value = Math.abs(module.thumbVal - module.secondThumbVal);
1093
+ }
1094
+ module.update.position(newValue);
1095
+ module.debug('Setting slider value to ' + value);
1096
+ if (typeof callback === 'function') {
1097
+ callback(value, module.thumbVal, module.secondThumbVal);
1098
+ }
1099
+ },
1100
+ position: function (newValue, $element) {
1101
+ const newPos = module.handleNewValuePosition(newValue);
1102
+ const $targetThumb = $element || $currThumb;
1103
+ let thumbVal = module.thumbVal || module.get.min();
1104
+ let secondThumbVal = module.secondThumbVal || module.get.min();
1105
+ if (settings.showThumbTooltip) {
1106
+ const precision = module.get.precision();
1107
+ $targetThumb.attr('data-tooltip', Math.round(newValue * precision) / precision);
1108
+ }
1109
+ if (module.is.range()) {
1110
+ if (!$targetThumb.hasClass('second')) {
1111
+ position = newPos;
1112
+ thumbVal = newValue;
1113
+ } else {
1114
+ secondPos = newPos;
1115
+ secondThumbVal = newValue;
1116
+ }
1117
+ } else {
1118
+ position = newPos;
1119
+ thumbVal = newValue;
1120
+ }
1121
+ module.set.active(thumbVal, secondThumbVal);
1122
+ let trackPosValue;
1123
+ let thumbPosValue;
1124
+ const min = module.get.min();
1125
+ const max = module.get.max();
1126
+ const thumbPosPercent = 100 * ((newValue - min) / (max - min));
1127
+ const trackStartPosPercent = 100 * ((Math.min(thumbVal, secondThumbVal) - min) / (max - min));
1128
+ const trackEndPosPercent = 100 * (1 - (Math.max(thumbVal, secondThumbVal) - min) / (max - min));
1129
+ if (module.is.vertical()) {
1130
+ if (module.is.reversed()) {
1131
+ thumbPosValue = { bottom: 'calc(' + thumbPosPercent + '% - ' + offset + 'px)', top: 'auto' };
1132
+ trackPosValue = { bottom: trackStartPosPercent + '%', top: trackEndPosPercent + '%' };
1133
+ } else {
1134
+ thumbPosValue = { top: 'calc(' + thumbPosPercent + '% - ' + offset + 'px)', bottom: 'auto' };
1135
+ trackPosValue = { top: trackStartPosPercent + '%', bottom: trackEndPosPercent + '%' };
1136
+ }
1137
+ } else if (module.is.reversed()) {
1138
+ thumbPosValue = { right: 'calc(' + thumbPosPercent + '% - ' + offset + 'px)', left: 'auto' };
1139
+ trackPosValue = { right: trackStartPosPercent + '%', left: trackEndPosPercent + '%' };
1140
+ } else {
1141
+ thumbPosValue = { left: 'calc(' + thumbPosPercent + '% - ' + offset + 'px)', right: 'auto' };
1142
+ trackPosValue = { left: trackStartPosPercent + '%', right: trackEndPosPercent + '%' };
1143
+ }
1144
+ $targetThumb.css(thumbPosValue);
1145
+ $trackFill.css(trackPosValue);
1146
+ module.debug('Setting slider position to ' + newPos);
1147
+ },
1148
+ labelPosition: function (ratio, $label) {
1149
+ const startMargin = module.get.trackStartMargin();
1150
+ const endMargin = module.get.trackEndMargin();
1151
+ const posDir = module.is.vertical()
1152
+ ? (module.is.reversed() ? 'bottom' : 'top')
1153
+ : (module.is.reversed() ? 'right' : 'left');
1154
+ const startMarginMod = module.is.reversed() && !module.is.vertical()
1155
+ ? ' - '
1156
+ : ' + ';
1157
+ const position = '(100% - ' + startMargin + ' - ' + endMargin + ') * ' + ratio;
1158
+ $label.css(posDir, 'calc(' + position + startMarginMod + startMargin + ')');
1159
+ },
1160
+ },
1161
+
1162
+ goto: {
1163
+ max: function () {
1164
+ module.set.value(module.get.max());
1165
+ },
1166
+ min: function () {
1167
+ module.set.value(module.get.min());
1168
+ },
1169
+ },
1170
+
1171
+ read: {
1172
+ metadata: function () {
1173
+ const data = {
1174
+ thumbVal: $module.data(metadata.thumbVal),
1175
+ secondThumbVal: $module.data(metadata.secondThumbVal),
1176
+ };
1177
+ if (data.thumbVal) {
1178
+ if (module.is.range() && data.secondThumbVal) {
1179
+ module.debug('Current value set from metadata', data.thumbVal, data.secondThumbVal);
1180
+ module.set.rangeValue(data.thumbVal, data.secondThumbVal);
1181
+ } else {
1182
+ module.debug('Current value set from metadata', data.thumbVal);
1183
+ module.set.value(data.thumbVal);
1184
+ }
1185
+ }
1186
+ },
1187
+ settings: function () {
1188
+ if (settings.start !== false) {
1189
+ if (module.is.range()) {
1190
+ const rangeDiff = settings.end - settings.start;
1191
+ if (rangeDiff < 0
1192
+ || (settings.minRange && rangeDiff < settings.minRange)
1193
+ || (settings.maxRange && rangeDiff > settings.maxRange)
1194
+ || (settings.minRange && settings.maxRange && settings.minRange > settings.maxRange)
1195
+ ) {
1196
+ module.error(error.invalidRanges, settings.start, settings.end, settings.minRange, settings.maxRange);
1197
+ }
1198
+ module.debug('Start position set from settings', settings.start, settings.end);
1199
+ module.set.rangeValue(settings.start, settings.end);
1200
+ } else {
1201
+ module.debug('Start position set from settings', settings.start);
1202
+ module.set.value(settings.start);
1203
+ }
1204
+ }
1205
+ },
1206
+ },
1207
+
1208
+ setting: function (name, value) {
1209
+ module.debug('Changing setting', name, value);
1210
+ if ($.isPlainObject(name)) {
1211
+ $.extend(true, settings, name);
1212
+ } else if (value !== undefined) {
1213
+ if ($.isPlainObject(settings[name])) {
1214
+ $.extend(true, settings[name], value);
1215
+ } else {
1216
+ settings[name] = value;
1217
+ }
1218
+ } else {
1219
+ return settings[name];
1220
+ }
1221
+ module.clear.cache();
1222
+ },
1223
+ internal: function (name, value) {
1224
+ if ($.isPlainObject(name)) {
1225
+ $.extend(true, module, name);
1226
+ } else if (value !== undefined) {
1227
+ module[name] = value;
1228
+ } else {
1229
+ return module[name];
1230
+ }
1231
+ },
1232
+ debug: function (...args) {
1233
+ if (!settings.silent && settings.debug) {
1234
+ if (settings.performance) {
1235
+ module.performance.log(args);
1236
+ } else {
1237
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
1238
+ module.debug.apply(console, args);
1239
+ }
1240
+ }
1241
+ },
1242
+ verbose: function (...args) {
1243
+ if (!settings.silent && settings.verbose && settings.debug) {
1244
+ if (settings.performance) {
1245
+ module.performance.log(args);
1246
+ } else {
1247
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
1248
+ module.verbose.apply(console, args);
1249
+ }
1250
+ }
1251
+ },
1252
+ error: function (...args) {
1253
+ if (!settings.silent) {
1254
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
1255
+ module.error.apply(console, args);
1256
+ }
1257
+ },
1258
+
1259
+ performance: {
1260
+ log: function (message) {
1261
+ let currentTime;
1262
+ let executionTime;
1263
+ let previousTime;
1264
+ if (settings.performance) {
1265
+ currentTime = Date.now();
1266
+ previousTime = time || currentTime;
1267
+ executionTime = currentTime - previousTime;
1268
+ time = currentTime;
1269
+ performance.push({
1270
+ Name: message[0],
1271
+ Arguments: message.slice(1),
1272
+ Element: element,
1273
+ 'Execution Time': executionTime,
1274
+ });
1275
+ }
1276
+ clearTimeout(module.performance.timer);
1277
+ module.performance.timer = setTimeout(function () {
1278
+ module.performance.display();
1279
+ }, 500);
1280
+ },
1281
+ display: function () {
1282
+ let title = settings.name + ':';
1283
+ let totalTime = 0;
1284
+ time = false;
1285
+ clearTimeout(module.performance.timer);
1286
+ $.each(performance, function (index, data) {
1287
+ totalTime += data['Execution Time'];
1288
+ });
1289
+ title += ' ' + totalTime + 'ms';
1290
+ if (performance.length > 0) {
1291
+ console.groupCollapsed(title);
1292
+ console.table(performance);
1293
+ console.groupEnd();
1294
+ }
1295
+ performance = [];
1296
+ },
1297
+ },
1298
+
1299
+ invoke: function (query, passedArguments = queryArguments, context = element) {
1300
+ let object = instance;
1301
+ let maxDepth;
1302
+ let found;
1303
+ let response;
1304
+ if (typeof query === 'string' && object !== undefined) {
1305
+ query = query.split(/[ .]/);
1306
+ maxDepth = query.length - 1;
1307
+ $.each(query, function (depth, value) {
1308
+ const camelCaseValue = depth !== maxDepth
1309
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
1310
+ : query;
1311
+ if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
1312
+ object = object[camelCaseValue];
1313
+ } else if (object[camelCaseValue] !== undefined) {
1314
+ found = object[camelCaseValue];
1315
+
1316
+ return false;
1317
+ } else if ($.isPlainObject(object[value]) && (depth !== maxDepth)) {
1318
+ object = object[value];
1319
+ } else if (object[value] !== undefined) {
1320
+ found = object[value];
1321
+
1322
+ return false;
1323
+ } else {
1324
+ module.error(error.method, query);
1325
+
1326
+ return false;
1327
+ }
1328
+ });
1329
+ }
1330
+ if (isFunction(found)) {
1331
+ response = found.apply(context, passedArguments);
1332
+ } else if (found !== undefined) {
1333
+ response = found;
1334
+ }
1335
+ if (Array.isArray(returnedValue)) {
1336
+ returnedValue.push(response);
1337
+ } else if (returnedValue !== undefined) {
1338
+ returnedValue = [returnedValue, response];
1339
+ } else if (response !== undefined) {
1340
+ returnedValue = response;
1341
+ }
1342
+
1343
+ return found;
1344
+ },
1345
+ };
1346
+
1347
+ if (methodInvoked) {
1348
+ if (instance === undefined) {
1349
+ module.initialize();
1350
+ }
1351
+ module.invoke(parameters);
1352
+ } else {
1353
+ if (instance !== undefined) {
1354
+ instance.invoke('destroy');
1355
+ }
1356
+ module.initialize();
1357
+ }
1358
+ });
1359
+
1360
+ return returnedValue !== undefined
1361
+ ? returnedValue
1362
+ : this;
1363
+ };
1364
+
1365
+ $.fn.slider.settings = {
1366
+
1367
+ silent: false,
1368
+ debug: false,
1369
+ verbose: false,
1370
+ performance: true,
1371
+
1372
+ name: 'Slider',
1373
+ namespace: 'slider',
1374
+
1375
+ error: {
1376
+ method: 'The method you called is not defined.',
1377
+ notrange: 'This slider is not a range slider',
1378
+ invalidRanges: 'Invalid range settings (start/end/minRange/maxRange)',
1379
+ invalidLetterNumber: 'Negative values or decimal places for labelType: "letter" are not supported',
1380
+ },
1381
+
1382
+ metadata: {
1383
+ thumbVal: 'thumbVal',
1384
+ secondThumbVal: 'secondThumbVal',
1385
+ },
1386
+
1387
+ min: 0,
1388
+ max: 20,
1389
+ step: 1,
1390
+ start: 0,
1391
+ end: 20,
1392
+ minRange: false,
1393
+ maxRange: false,
1394
+ labelType: 'number',
1395
+ showLabelTicks: false,
1396
+ smooth: false,
1397
+ autoAdjustLabels: true,
1398
+ labelDistance: 100,
1399
+ preventCrossover: true,
1400
+ fireOnInit: false,
1401
+ interpretLabel: false,
1402
+ letters: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
1403
+
1404
+ // the decimal place to round to if step is undefined
1405
+ decimalPlaces: 2,
1406
+
1407
+ // page up/down multiplier. How many more times the steps to take on page up/down press
1408
+ pageMultiplier: 2,
1409
+
1410
+ selector: {},
1411
+
1412
+ className: {
1413
+ reversed: 'reversed',
1414
+ disabled: 'disabled',
1415
+ labeled: 'labeled',
1416
+ ticked: 'ticked',
1417
+ vertical: 'vertical',
1418
+ range: 'range',
1419
+ smooth: 'smooth',
1420
+ label: 'label',
1421
+ active: 'active',
1422
+ },
1423
+
1424
+ keys: {
1425
+ pageUp: 33,
1426
+ pageDown: 34,
1427
+ leftArrow: 37,
1428
+ upArrow: 38,
1429
+ rightArrow: 39,
1430
+ downArrow: 40,
1431
+ },
1432
+
1433
+ restrictedLabels: [],
1434
+ highlightRange: false,
1435
+ showThumbTooltip: false,
1436
+ tooltipConfig: {
1437
+ position: 'top center',
1438
+ variation: 'tiny black',
1439
+ },
1440
+
1441
+ labelTypes: {
1442
+ number: 'number',
1443
+ letter: 'letter',
1444
+ },
1445
+
1446
+ onChange: function (value, thumbVal, secondThumbVal) {},
1447
+ onMove: function (value, thumbVal, secondThumbVal) {},
1448
+ };
1449
+ })(jQuery, window, document);