c80_estate 0.1.0.9 → 0.1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/app/admin/c80_estate/admin_user.rb +4 -1
  3. data/app/admin/c80_estate/areas.rb +30 -20
  4. data/app/admin/c80_estate/astatuses.rb +1 -0
  5. data/app/admin/c80_estate/comments.rb +3 -1
  6. data/app/admin/c80_estate/dashboard.rb +14 -4
  7. data/app/admin/c80_estate/properties.rb +1 -1
  8. data/app/admin/c80_estate/pstats.rb +1 -0
  9. data/app/assets/javascript/c80_estate/backend/admin/areas.js +180 -19
  10. data/app/assets/javascript/c80_estate/backend/admin/pstats.js +155 -147
  11. data/app/assets/javascript/c80_estate/lib/bootstrap-slider.js +1641 -0
  12. data/app/assets/stylesheets/c80_estate/backend/admin_areas.scss +7 -3
  13. data/app/assets/stylesheets/c80_estate/backend/admin_pstats.scss +19 -11
  14. data/app/assets/stylesheets/c80_estate/backend/common.scss +5 -0
  15. data/app/controllers/c80_estate/ajax_areas_controller.rb +38 -0
  16. data/app/helpers/c80_estate/app_helper.rb +45 -36
  17. data/app/models/c80_estate/area.rb +94 -0
  18. data/app/models/c80_estate/item_prop.rb +4 -2
  19. data/app/models/c80_estate/owner.rb +8 -2
  20. data/app/models/c80_estate/pstat.rb +53 -35
  21. data/app/views/admin/dashboard/_prop_in_list.html.erb +1 -2
  22. data/app/views/c80_estate/ajax_areas/exel_import.html.erb +1 -0
  23. data/app/views/c80_estate/ajax_areas/exel_import.js.erb +6 -0
  24. data/app/views/c80_estate/shared/_form_upload_areas_excel.erb +37 -0
  25. data/app/views/c80_estate/shared/_table_properties_coef_busy.html.erb +12 -8
  26. data/app/views/c80_estate/shared/_table_properties_coef_busy_sq.html.erb +12 -8
  27. data/config/routes.rb +2 -0
  28. data/lib/c80_estate/version.rb +1 -1
  29. metadata +7 -3
  30. data/app/assets/javascript/c80_estate/lib/bootstrap-slider.min.js +0 -29
@@ -0,0 +1,1641 @@
1
+ /*! =======================================================
2
+ VERSION 9.1.1
3
+ ========================================================= */
4
+ "use strict";
5
+
6
+ function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
7
+
8
+ /*! =========================================================
9
+ * bootstrap-slider.js
10
+ *
11
+ * Maintainers:
12
+ * Kyle Kemp
13
+ * - Twitter: @seiyria
14
+ * - Github: seiyria
15
+ * Rohit Kalkur
16
+ * - Twitter: @Rovolutionary
17
+ * - Github: rovolution
18
+ *
19
+ * =========================================================
20
+ *
21
+ * Licensed under the Apache License, Version 2.0 (the "License");
22
+ * you may not use this file except in compliance with the License.
23
+ * You may obtain a copy of the License at
24
+ *
25
+ * http://www.apache.org/licenses/LICENSE-2.0
26
+ *
27
+ * Unless required by applicable law or agreed to in writing, software
28
+ * distributed under the License is distributed on an "AS IS" BASIS,
29
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30
+ * See the License for the specific language governing permissions and
31
+ * limitations under the License.
32
+ * ========================================================= */
33
+
34
+ /**
35
+ * Bridget makes jQuery widgets
36
+ * v1.0.1
37
+ * MIT license
38
+ */
39
+
40
+ (function (factory) {
41
+ if (typeof define === "function" && define.amd) {
42
+ define(["jquery"], factory);
43
+ } else if ((typeof module === "undefined" ? "undefined" : _typeof(module)) === "object" && module.exports) {
44
+ var jQuery;
45
+ try {
46
+ jQuery = require("jquery");
47
+ } catch (err) {
48
+ jQuery = null;
49
+ }
50
+ module.exports = factory(jQuery);
51
+ } else if (window) {
52
+ window.Slider = factory(window.jQuery);
53
+ }
54
+ })(function ($) {
55
+ // Constants
56
+ var NAMESPACE_MAIN = 'slider';
57
+ var NAMESPACE_ALTERNATE = 'bootstrapSlider';
58
+
59
+ // Polyfill console methods
60
+ if (!window.console) {
61
+ window.console = {};
62
+ }
63
+ if (!window.console.log) {
64
+ window.console.log = function () {};
65
+ }
66
+ if (!window.console.warn) {
67
+ window.console.warn = function () {};
68
+ }
69
+
70
+ // Reference to Slider constructor
71
+ var Slider;
72
+
73
+ (function ($) {
74
+
75
+ 'use strict';
76
+
77
+ // -------------------------- utils -------------------------- //
78
+
79
+ var slice = Array.prototype.slice;
80
+
81
+ function noop() {}
82
+
83
+ // -------------------------- definition -------------------------- //
84
+
85
+ function defineBridget($) {
86
+
87
+ // bail if no jQuery
88
+ if (!$) {
89
+ return;
90
+ }
91
+
92
+ // -------------------------- addOptionMethod -------------------------- //
93
+
94
+ /**
95
+ * adds option method -> $().plugin('option', {...})
96
+ * @param {Function} PluginClass - constructor class
97
+ */
98
+ function addOptionMethod(PluginClass) {
99
+ // don't overwrite original option method
100
+ if (PluginClass.prototype.option) {
101
+ return;
102
+ }
103
+
104
+ // option setter
105
+ PluginClass.prototype.option = function (opts) {
106
+ // bail out if not an object
107
+ if (!$.isPlainObject(opts)) {
108
+ return;
109
+ }
110
+ this.options = $.extend(true, this.options, opts);
111
+ };
112
+ }
113
+
114
+ // -------------------------- plugin bridge -------------------------- //
115
+
116
+ // helper function for logging errors
117
+ // $.error breaks jQuery chaining
118
+ var logError = typeof console === 'undefined' ? noop : function (message) {
119
+ console.error(message);
120
+ };
121
+
122
+ /**
123
+ * jQuery plugin bridge, access methods like $elem.plugin('method')
124
+ * @param {String} namespace - plugin name
125
+ * @param {Function} PluginClass - constructor class
126
+ */
127
+ function bridge(namespace, PluginClass) {
128
+ // add to jQuery fn namespace
129
+ $.fn[namespace] = function (options) {
130
+ if (typeof options === 'string') {
131
+ // call plugin method when first argument is a string
132
+ // get arguments for method
133
+ var args = slice.call(arguments, 1);
134
+
135
+ for (var i = 0, len = this.length; i < len; i++) {
136
+ var elem = this[i];
137
+ var instance = $.data(elem, namespace);
138
+ if (!instance) {
139
+ logError("cannot call methods on " + namespace + " prior to initialization; " + "attempted to call '" + options + "'");
140
+ continue;
141
+ }
142
+ if (!$.isFunction(instance[options]) || options.charAt(0) === '_') {
143
+ logError("no such method '" + options + "' for " + namespace + " instance");
144
+ continue;
145
+ }
146
+
147
+ // trigger method with arguments
148
+ var returnValue = instance[options].apply(instance, args);
149
+
150
+ // break look and return first value if provided
151
+ if (returnValue !== undefined && returnValue !== instance) {
152
+ return returnValue;
153
+ }
154
+ }
155
+ // return this if no return value
156
+ return this;
157
+ } else {
158
+ var objects = this.map(function () {
159
+ var instance = $.data(this, namespace);
160
+ if (instance) {
161
+ // apply options & init
162
+ instance.option(options);
163
+ instance._init();
164
+ } else {
165
+ // initialize new instance
166
+ instance = new PluginClass(this, options);
167
+ $.data(this, namespace, instance);
168
+ }
169
+ return $(this);
170
+ });
171
+
172
+ if (!objects || objects.length > 1) {
173
+ return objects;
174
+ } else {
175
+ return objects[0];
176
+ }
177
+ }
178
+ };
179
+ }
180
+
181
+ // -------------------------- bridget -------------------------- //
182
+
183
+ /**
184
+ * converts a Prototypical class into a proper jQuery plugin
185
+ * the class must have a ._init method
186
+ * @param {String} namespace - plugin name, used in $().pluginName
187
+ * @param {Function} PluginClass - constructor class
188
+ */
189
+ $.bridget = function (namespace, PluginClass) {
190
+ addOptionMethod(PluginClass);
191
+ bridge(namespace, PluginClass);
192
+ };
193
+
194
+ return $.bridget;
195
+ }
196
+
197
+ // get jquery from browser global
198
+ defineBridget($);
199
+ })($);
200
+
201
+ /*************************************************
202
+ BOOTSTRAP-SLIDER SOURCE CODE
203
+ **************************************************/
204
+
205
+ (function ($) {
206
+
207
+ var ErrorMsgs = {
208
+ formatInvalidInputErrorMsg: function formatInvalidInputErrorMsg(input) {
209
+ return "Invalid input value '" + input + "' passed in";
210
+ },
211
+ callingContextNotSliderInstance: "Calling context element does not have instance of Slider bound to it. Check your code to make sure the JQuery object returned from the call to the slider() initializer is calling the method"
212
+ };
213
+
214
+ var SliderScale = {
215
+ linear: {
216
+ toValue: function toValue(percentage) {
217
+ var rawValue = percentage / 100 * (this.options.max - this.options.min);
218
+ var shouldAdjustWithBase = true;
219
+ if (this.options.ticks_positions.length > 0) {
220
+ var minv,
221
+ maxv,
222
+ minp,
223
+ maxp = 0;
224
+ for (var i = 1; i < this.options.ticks_positions.length; i++) {
225
+ if (percentage <= this.options.ticks_positions[i]) {
226
+ minv = this.options.ticks[i - 1];
227
+ minp = this.options.ticks_positions[i - 1];
228
+ maxv = this.options.ticks[i];
229
+ maxp = this.options.ticks_positions[i];
230
+
231
+ break;
232
+ }
233
+ }
234
+ var partialPercentage = (percentage - minp) / (maxp - minp);
235
+ rawValue = minv + partialPercentage * (maxv - minv);
236
+ shouldAdjustWithBase = false;
237
+ }
238
+
239
+ var adjustment = shouldAdjustWithBase ? this.options.min : 0;
240
+ var value = adjustment + Math.round(rawValue / this.options.step) * this.options.step;
241
+ if (value < this.options.min) {
242
+ return this.options.min;
243
+ } else if (value > this.options.max) {
244
+ return this.options.max;
245
+ } else {
246
+ return value;
247
+ }
248
+ },
249
+ toPercentage: function toPercentage(value) {
250
+ if (this.options.max === this.options.min) {
251
+ return 0;
252
+ }
253
+
254
+ if (this.options.ticks_positions.length > 0) {
255
+ var minv,
256
+ maxv,
257
+ minp,
258
+ maxp = 0;
259
+ for (var i = 0; i < this.options.ticks.length; i++) {
260
+ if (value <= this.options.ticks[i]) {
261
+ minv = i > 0 ? this.options.ticks[i - 1] : 0;
262
+ minp = i > 0 ? this.options.ticks_positions[i - 1] : 0;
263
+ maxv = this.options.ticks[i];
264
+ maxp = this.options.ticks_positions[i];
265
+
266
+ break;
267
+ }
268
+ }
269
+ if (i > 0) {
270
+ var partialPercentage = (value - minv) / (maxv - minv);
271
+ return minp + partialPercentage * (maxp - minp);
272
+ }
273
+ }
274
+
275
+ return 100 * (value - this.options.min) / (this.options.max - this.options.min);
276
+ }
277
+ },
278
+
279
+ logarithmic: {
280
+ /* Based on http://stackoverflow.com/questions/846221/logarithmic-slider */
281
+ toValue: function toValue(percentage) {
282
+ var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
283
+ var max = Math.log(this.options.max);
284
+ var value = Math.exp(min + (max - min) * percentage / 100);
285
+ value = this.options.min + Math.round((value - this.options.min) / this.options.step) * this.options.step;
286
+ /* Rounding to the nearest step could exceed the min or
287
+ * max, so clip to those values. */
288
+ if (value < this.options.min) {
289
+ return this.options.min;
290
+ } else if (value > this.options.max) {
291
+ return this.options.max;
292
+ } else {
293
+ return value;
294
+ }
295
+ },
296
+ toPercentage: function toPercentage(value) {
297
+ if (this.options.max === this.options.min) {
298
+ return 0;
299
+ } else {
300
+ var max = Math.log(this.options.max);
301
+ var min = this.options.min === 0 ? 0 : Math.log(this.options.min);
302
+ var v = value === 0 ? 0 : Math.log(value);
303
+ return 100 * (v - min) / (max - min);
304
+ }
305
+ }
306
+ }
307
+ };
308
+
309
+ /*************************************************
310
+ CONSTRUCTOR
311
+ **************************************************/
312
+ Slider = function (element, options) {
313
+ createNewSlider.call(this, element, options);
314
+ return this;
315
+ };
316
+
317
+ function createNewSlider(element, options) {
318
+
319
+ /*
320
+ The internal state object is used to store data about the current 'state' of slider.
321
+ This includes values such as the `value`, `enabled`, etc...
322
+ */
323
+ this._state = {
324
+ value: null,
325
+ enabled: null,
326
+ offset: null,
327
+ size: null,
328
+ percentage: null,
329
+ inDrag: false,
330
+ over: false
331
+ };
332
+
333
+ if (typeof element === "string") {
334
+ this.element = document.querySelector(element);
335
+ } else if (element instanceof HTMLElement) {
336
+ this.element = element;
337
+ }
338
+
339
+ /*************************************************
340
+ Process Options
341
+ **************************************************/
342
+ options = options ? options : {};
343
+ var optionTypes = Object.keys(this.defaultOptions);
344
+
345
+ for (var i = 0; i < optionTypes.length; i++) {
346
+ var optName = optionTypes[i];
347
+
348
+ // First check if an option was passed in via the constructor
349
+ var val = options[optName];
350
+ // If no data attrib, then check data atrributes
351
+ val = typeof val !== 'undefined' ? val : getDataAttrib(this.element, optName);
352
+ // Finally, if nothing was specified, use the defaults
353
+ val = val !== null ? val : this.defaultOptions[optName];
354
+
355
+ // Set all options on the instance of the Slider
356
+ if (!this.options) {
357
+ this.options = {};
358
+ }
359
+ this.options[optName] = val;
360
+ }
361
+
362
+ /*
363
+ Validate `tooltip_position` against 'orientation`
364
+ - if `tooltip_position` is incompatible with orientation, swith it to a default compatible with specified `orientation`
365
+ -- default for "vertical" -> "right"
366
+ -- default for "horizontal" -> "left"
367
+ */
368
+ if (this.options.orientation === "vertical" && (this.options.tooltip_position === "top" || this.options.tooltip_position === "bottom")) {
369
+
370
+ this.options.tooltip_position = "right";
371
+ } else if (this.options.orientation === "horizontal" && (this.options.tooltip_position === "left" || this.options.tooltip_position === "right")) {
372
+
373
+ this.options.tooltip_position = "top";
374
+ }
375
+
376
+ function getDataAttrib(element, optName) {
377
+ var dataName = "data-slider-" + optName.replace(/_/g, '-');
378
+ var dataValString = element.getAttribute(dataName);
379
+
380
+ try {
381
+ return JSON.parse(dataValString);
382
+ } catch (err) {
383
+ return dataValString;
384
+ }
385
+ }
386
+
387
+ /*************************************************
388
+ Create Markup
389
+ **************************************************/
390
+
391
+ var origWidth = this.element.style.width;
392
+ var updateSlider = false;
393
+ var parent = this.element.parentNode;
394
+ var sliderTrackSelection;
395
+ var sliderTrackLow, sliderTrackHigh;
396
+ var sliderMinHandle;
397
+ var sliderMaxHandle;
398
+
399
+ if (this.sliderElem) {
400
+ updateSlider = true;
401
+ } else {
402
+ /* Create elements needed for slider */
403
+ this.sliderElem = document.createElement("div");
404
+ this.sliderElem.className = "slider";
405
+
406
+ /* Create slider track elements */
407
+ var sliderTrack = document.createElement("div");
408
+ sliderTrack.className = "slider-track";
409
+
410
+ sliderTrackLow = document.createElement("div");
411
+ sliderTrackLow.className = "slider-track-low";
412
+
413
+ sliderTrackSelection = document.createElement("div");
414
+ sliderTrackSelection.className = "slider-selection";
415
+
416
+ sliderTrackHigh = document.createElement("div");
417
+ sliderTrackHigh.className = "slider-track-high";
418
+
419
+ sliderMinHandle = document.createElement("div");
420
+ sliderMinHandle.className = "slider-handle min-slider-handle";
421
+ sliderMinHandle.setAttribute('role', 'slider');
422
+ sliderMinHandle.setAttribute('aria-valuemin', this.options.min);
423
+ sliderMinHandle.setAttribute('aria-valuemax', this.options.max);
424
+
425
+ sliderMaxHandle = document.createElement("div");
426
+ sliderMaxHandle.className = "slider-handle max-slider-handle";
427
+ sliderMaxHandle.setAttribute('role', 'slider');
428
+ sliderMaxHandle.setAttribute('aria-valuemin', this.options.min);
429
+ sliderMaxHandle.setAttribute('aria-valuemax', this.options.max);
430
+
431
+ sliderTrack.appendChild(sliderTrackLow);
432
+ sliderTrack.appendChild(sliderTrackSelection);
433
+ sliderTrack.appendChild(sliderTrackHigh);
434
+
435
+ /* Add aria-labelledby to handle's */
436
+ var isLabelledbyArray = Array.isArray(this.options.labelledby);
437
+ if (isLabelledbyArray && this.options.labelledby[0]) {
438
+ sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby[0]);
439
+ }
440
+ if (isLabelledbyArray && this.options.labelledby[1]) {
441
+ sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby[1]);
442
+ }
443
+ if (!isLabelledbyArray && this.options.labelledby) {
444
+ sliderMinHandle.setAttribute('aria-labelledby', this.options.labelledby);
445
+ sliderMaxHandle.setAttribute('aria-labelledby', this.options.labelledby);
446
+ }
447
+
448
+ /* Create ticks */
449
+ this.ticks = [];
450
+ if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
451
+ this.ticksContainer = document.createElement('div');
452
+ this.ticksContainer.className = 'slider-tick-container';
453
+
454
+ for (i = 0; i < this.options.ticks.length; i++) {
455
+ var tick = document.createElement('div');
456
+ tick.className = 'slider-tick';
457
+ this.ticks.push(tick);
458
+ this.ticksContainer.appendChild(tick);
459
+ }
460
+
461
+ sliderTrackSelection.className += " tick-slider-selection";
462
+ }
463
+
464
+ this.tickLabels = [];
465
+ if (Array.isArray(this.options.ticks_labels) && this.options.ticks_labels.length > 0) {
466
+ this.tickLabelContainer = document.createElement('div');
467
+ this.tickLabelContainer.className = 'slider-tick-label-container';
468
+
469
+ for (i = 0; i < this.options.ticks_labels.length; i++) {
470
+ var label = document.createElement('div');
471
+ var noTickPositionsSpecified = this.options.ticks_positions.length === 0;
472
+ var tickLabelsIndex = this.options.reversed && noTickPositionsSpecified ? this.options.ticks_labels.length - (i + 1) : i;
473
+ label.className = 'slider-tick-label';
474
+ label.innerHTML = this.options.ticks_labels[tickLabelsIndex];
475
+
476
+ this.tickLabels.push(label);
477
+ this.tickLabelContainer.appendChild(label);
478
+ }
479
+ }
480
+
481
+ var createAndAppendTooltipSubElements = function createAndAppendTooltipSubElements(tooltipElem) {
482
+ var arrow = document.createElement("div");
483
+ arrow.className = "tooltip-arrow";
484
+
485
+ var inner = document.createElement("div");
486
+ inner.className = "tooltip-inner";
487
+
488
+ tooltipElem.appendChild(arrow);
489
+ tooltipElem.appendChild(inner);
490
+ };
491
+
492
+ /* Create tooltip elements */
493
+ var sliderTooltip = document.createElement("div");
494
+ sliderTooltip.className = "tooltip tooltip-main";
495
+ sliderTooltip.setAttribute('role', 'presentation');
496
+ createAndAppendTooltipSubElements(sliderTooltip);
497
+
498
+ var sliderTooltipMin = document.createElement("div");
499
+ sliderTooltipMin.className = "tooltip tooltip-min";
500
+ sliderTooltipMin.setAttribute('role', 'presentation');
501
+ createAndAppendTooltipSubElements(sliderTooltipMin);
502
+
503
+ var sliderTooltipMax = document.createElement("div");
504
+ sliderTooltipMax.className = "tooltip tooltip-max";
505
+ sliderTooltipMax.setAttribute('role', 'presentation');
506
+ createAndAppendTooltipSubElements(sliderTooltipMax);
507
+
508
+ /* Append components to sliderElem */
509
+ this.sliderElem.appendChild(sliderTrack);
510
+ this.sliderElem.appendChild(sliderTooltip);
511
+ this.sliderElem.appendChild(sliderTooltipMin);
512
+ this.sliderElem.appendChild(sliderTooltipMax);
513
+
514
+ if (this.tickLabelContainer) {
515
+ this.sliderElem.appendChild(this.tickLabelContainer);
516
+ }
517
+ if (this.ticksContainer) {
518
+ this.sliderElem.appendChild(this.ticksContainer);
519
+ }
520
+
521
+ this.sliderElem.appendChild(sliderMinHandle);
522
+ this.sliderElem.appendChild(sliderMaxHandle);
523
+
524
+ /* Append slider element to parent container, right before the original <input> element */
525
+ parent.insertBefore(this.sliderElem, this.element);
526
+
527
+ /* Hide original <input> element */
528
+ this.element.style.display = "none";
529
+ }
530
+ /* If JQuery exists, cache JQ references */
531
+ if ($) {
532
+ this.$element = $(this.element);
533
+ this.$sliderElem = $(this.sliderElem);
534
+ }
535
+
536
+ /*************************************************
537
+ Setup
538
+ **************************************************/
539
+ this.eventToCallbackMap = {};
540
+ this.sliderElem.id = this.options.id;
541
+
542
+ this.touchCapable = 'ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch;
543
+
544
+ this.touchX = 0;
545
+ this.touchY = 0;
546
+
547
+ this.tooltip = this.sliderElem.querySelector('.tooltip-main');
548
+ this.tooltipInner = this.tooltip.querySelector('.tooltip-inner');
549
+
550
+ this.tooltip_min = this.sliderElem.querySelector('.tooltip-min');
551
+ this.tooltipInner_min = this.tooltip_min.querySelector('.tooltip-inner');
552
+
553
+ this.tooltip_max = this.sliderElem.querySelector('.tooltip-max');
554
+ this.tooltipInner_max = this.tooltip_max.querySelector('.tooltip-inner');
555
+
556
+ if (SliderScale[this.options.scale]) {
557
+ this.options.scale = SliderScale[this.options.scale];
558
+ }
559
+
560
+ if (updateSlider === true) {
561
+ // Reset classes
562
+ this._removeClass(this.sliderElem, 'slider-horizontal');
563
+ this._removeClass(this.sliderElem, 'slider-vertical');
564
+ this._removeClass(this.tooltip, 'hide');
565
+ this._removeClass(this.tooltip_min, 'hide');
566
+ this._removeClass(this.tooltip_max, 'hide');
567
+
568
+ // Undo existing inline styles for track
569
+ ["left", "top", "width", "height"].forEach(function (prop) {
570
+ this._removeProperty(this.trackLow, prop);
571
+ this._removeProperty(this.trackSelection, prop);
572
+ this._removeProperty(this.trackHigh, prop);
573
+ }, this);
574
+
575
+ // Undo inline styles on handles
576
+ [this.handle1, this.handle2].forEach(function (handle) {
577
+ this._removeProperty(handle, 'left');
578
+ this._removeProperty(handle, 'top');
579
+ }, this);
580
+
581
+ // Undo inline styles and classes on tooltips
582
+ [this.tooltip, this.tooltip_min, this.tooltip_max].forEach(function (tooltip) {
583
+ this._removeProperty(tooltip, 'left');
584
+ this._removeProperty(tooltip, 'top');
585
+ this._removeProperty(tooltip, 'margin-left');
586
+ this._removeProperty(tooltip, 'margin-top');
587
+
588
+ this._removeClass(tooltip, 'right');
589
+ this._removeClass(tooltip, 'top');
590
+ }, this);
591
+ }
592
+
593
+ if (this.options.orientation === 'vertical') {
594
+ this._addClass(this.sliderElem, 'slider-vertical');
595
+ this.stylePos = 'top';
596
+ this.mousePos = 'pageY';
597
+ this.sizePos = 'offsetHeight';
598
+ } else {
599
+ this._addClass(this.sliderElem, 'slider-horizontal');
600
+ this.sliderElem.style.width = origWidth;
601
+ this.options.orientation = 'horizontal';
602
+ this.stylePos = 'left';
603
+ this.mousePos = 'pageX';
604
+ this.sizePos = 'offsetWidth';
605
+ }
606
+ this._setTooltipPosition();
607
+ /* In case ticks are specified, overwrite the min and max bounds */
608
+ if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
609
+ this.options.max = Math.max.apply(Math, this.options.ticks);
610
+ this.options.min = Math.min.apply(Math, this.options.ticks);
611
+ }
612
+
613
+ if (Array.isArray(this.options.value)) {
614
+ this.options.range = true;
615
+ this._state.value = this.options.value;
616
+ } else if (this.options.range) {
617
+ // User wants a range, but value is not an array
618
+ this._state.value = [this.options.value, this.options.max];
619
+ } else {
620
+ this._state.value = this.options.value;
621
+ }
622
+
623
+ this.trackLow = sliderTrackLow || this.trackLow;
624
+ this.trackSelection = sliderTrackSelection || this.trackSelection;
625
+ this.trackHigh = sliderTrackHigh || this.trackHigh;
626
+
627
+ if (this.options.selection === 'none') {
628
+ this._addClass(this.trackLow, 'hide');
629
+ this._addClass(this.trackSelection, 'hide');
630
+ this._addClass(this.trackHigh, 'hide');
631
+ }
632
+
633
+ this.handle1 = sliderMinHandle || this.handle1;
634
+ this.handle2 = sliderMaxHandle || this.handle2;
635
+
636
+ if (updateSlider === true) {
637
+ // Reset classes
638
+ this._removeClass(this.handle1, 'round triangle');
639
+ this._removeClass(this.handle2, 'round triangle hide');
640
+
641
+ for (i = 0; i < this.ticks.length; i++) {
642
+ this._removeClass(this.ticks[i], 'round triangle hide');
643
+ }
644
+ }
645
+
646
+ var availableHandleModifiers = ['round', 'triangle', 'custom'];
647
+ var isValidHandleType = availableHandleModifiers.indexOf(this.options.handle) !== -1;
648
+ if (isValidHandleType) {
649
+ this._addClass(this.handle1, this.options.handle);
650
+ this._addClass(this.handle2, this.options.handle);
651
+
652
+ for (i = 0; i < this.ticks.length; i++) {
653
+ this._addClass(this.ticks[i], this.options.handle);
654
+ }
655
+ }
656
+
657
+ this._state.offset = this._offset(this.sliderElem);
658
+ this._state.size = this.sliderElem[this.sizePos];
659
+ this.setValue(this._state.value);
660
+
661
+ /******************************************
662
+ Bind Event Listeners
663
+ ******************************************/
664
+
665
+ // Bind keyboard handlers
666
+ this.handle1Keydown = this._keydown.bind(this, 0);
667
+ this.handle1.addEventListener("keydown", this.handle1Keydown, false);
668
+
669
+ this.handle2Keydown = this._keydown.bind(this, 1);
670
+ this.handle2.addEventListener("keydown", this.handle2Keydown, false);
671
+
672
+ this.mousedown = this._mousedown.bind(this);
673
+ this.touchstart = this._touchstart.bind(this);
674
+ this.touchmove = this._touchmove.bind(this);
675
+
676
+ if (this.touchCapable) {
677
+ // Bind touch handlers
678
+ this.sliderElem.addEventListener("touchstart", this.touchstart, false);
679
+ this.sliderElem.addEventListener("touchmove", this.touchmove, false);
680
+ }
681
+ this.sliderElem.addEventListener("mousedown", this.mousedown, false);
682
+
683
+ // Bind window handlers
684
+ this.resize = this._resize.bind(this);
685
+ window.addEventListener("resize", this.resize, false);
686
+
687
+ // Bind tooltip-related handlers
688
+ if (this.options.tooltip === 'hide') {
689
+ this._addClass(this.tooltip, 'hide');
690
+ this._addClass(this.tooltip_min, 'hide');
691
+ this._addClass(this.tooltip_max, 'hide');
692
+ } else if (this.options.tooltip === 'always') {
693
+ this._showTooltip();
694
+ this._alwaysShowTooltip = true;
695
+ } else {
696
+ this.showTooltip = this._showTooltip.bind(this);
697
+ this.hideTooltip = this._hideTooltip.bind(this);
698
+
699
+ this.sliderElem.addEventListener("mouseenter", this.showTooltip, false);
700
+ this.sliderElem.addEventListener("mouseleave", this.hideTooltip, false);
701
+
702
+ this.handle1.addEventListener("focus", this.showTooltip, false);
703
+ this.handle1.addEventListener("blur", this.hideTooltip, false);
704
+
705
+ this.handle2.addEventListener("focus", this.showTooltip, false);
706
+ this.handle2.addEventListener("blur", this.hideTooltip, false);
707
+ }
708
+
709
+ if (this.options.enabled) {
710
+ this.enable();
711
+ } else {
712
+ this.disable();
713
+ }
714
+ }
715
+
716
+ /*************************************************
717
+ INSTANCE PROPERTIES/METHODS
718
+ - Any methods bound to the prototype are considered
719
+ part of the plugin's `public` interface
720
+ **************************************************/
721
+ Slider.prototype = {
722
+ _init: function _init() {}, // NOTE: Must exist to support bridget
723
+
724
+ constructor: Slider,
725
+
726
+ defaultOptions: {
727
+ id: "",
728
+ min: 0,
729
+ max: 10,
730
+ step: 1,
731
+ precision: 0,
732
+ orientation: 'horizontal',
733
+ value: 5,
734
+ range: false,
735
+ selection: 'before',
736
+ tooltip: 'show',
737
+ tooltip_split: false,
738
+ handle: 'round',
739
+ reversed: false,
740
+ enabled: true,
741
+ formatter: function formatter(val) {
742
+ if (Array.isArray(val)) {
743
+ return val[0] + " : " + val[1];
744
+ } else {
745
+ return val;
746
+ }
747
+ },
748
+ natural_arrow_keys: false,
749
+ ticks: [],
750
+ ticks_positions: [],
751
+ ticks_labels: [],
752
+ ticks_snap_bounds: 0,
753
+ scale: 'linear',
754
+ focus: false,
755
+ tooltip_position: null,
756
+ labelledby: null
757
+ },
758
+
759
+ getElement: function getElement() {
760
+ return this.sliderElem;
761
+ },
762
+
763
+ getValue: function getValue() {
764
+ if (this.options.range) {
765
+ return this._state.value;
766
+ } else {
767
+ return this._state.value[0];
768
+ }
769
+ },
770
+
771
+ setValue: function setValue(val, triggerSlideEvent, triggerChangeEvent) {
772
+ if (!val) {
773
+ val = 0;
774
+ }
775
+ var oldValue = this.getValue();
776
+ this._state.value = this._validateInputValue(val);
777
+ var applyPrecision = this._applyPrecision.bind(this);
778
+
779
+ if (this.options.range) {
780
+ this._state.value[0] = applyPrecision(this._state.value[0]);
781
+ this._state.value[1] = applyPrecision(this._state.value[1]);
782
+
783
+ this._state.value[0] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[0]));
784
+ this._state.value[1] = Math.max(this.options.min, Math.min(this.options.max, this._state.value[1]));
785
+ } else {
786
+ this._state.value = applyPrecision(this._state.value);
787
+ this._state.value = [Math.max(this.options.min, Math.min(this.options.max, this._state.value))];
788
+ this._addClass(this.handle2, 'hide');
789
+ if (this.options.selection === 'after') {
790
+ this._state.value[1] = this.options.max;
791
+ } else {
792
+ this._state.value[1] = this.options.min;
793
+ }
794
+ }
795
+
796
+ if (this.options.max > this.options.min) {
797
+ this._state.percentage = [this._toPercentage(this._state.value[0]), this._toPercentage(this._state.value[1]), this.options.step * 100 / (this.options.max - this.options.min)];
798
+ } else {
799
+ this._state.percentage = [0, 0, 100];
800
+ }
801
+
802
+ this._layout();
803
+ var newValue = this.options.range ? this._state.value : this._state.value[0];
804
+
805
+ this._setDataVal(newValue);
806
+ if (triggerSlideEvent === true) {
807
+ this._trigger('slide', newValue);
808
+ }
809
+ if (oldValue !== newValue && triggerChangeEvent === true) {
810
+ this._trigger('change', {
811
+ oldValue: oldValue,
812
+ newValue: newValue
813
+ });
814
+ }
815
+
816
+ return this;
817
+ },
818
+
819
+ destroy: function destroy() {
820
+ // Remove event handlers on slider elements
821
+ this._removeSliderEventHandlers();
822
+
823
+ // Remove the slider from the DOM
824
+ this.sliderElem.parentNode.removeChild(this.sliderElem);
825
+ /* Show original <input> element */
826
+ this.element.style.display = "";
827
+
828
+ // Clear out custom event bindings
829
+ this._cleanUpEventCallbacksMap();
830
+
831
+ // Remove data values
832
+ this.element.removeAttribute("data");
833
+
834
+ // Remove JQuery handlers/data
835
+ if ($) {
836
+ this._unbindJQueryEventHandlers();
837
+ this.$element.removeData('slider');
838
+ }
839
+ },
840
+
841
+ disable: function disable() {
842
+ this._state.enabled = false;
843
+ this.handle1.removeAttribute("tabindex");
844
+ this.handle2.removeAttribute("tabindex");
845
+ this._addClass(this.sliderElem, 'slider-disabled');
846
+ this._trigger('slideDisabled');
847
+
848
+ return this;
849
+ },
850
+
851
+ enable: function enable() {
852
+ this._state.enabled = true;
853
+ this.handle1.setAttribute("tabindex", 0);
854
+ this.handle2.setAttribute("tabindex", 0);
855
+ this._removeClass(this.sliderElem, 'slider-disabled');
856
+ this._trigger('slideEnabled');
857
+
858
+ return this;
859
+ },
860
+
861
+ toggle: function toggle() {
862
+ if (this._state.enabled) {
863
+ this.disable();
864
+ } else {
865
+ this.enable();
866
+ }
867
+ return this;
868
+ },
869
+
870
+ isEnabled: function isEnabled() {
871
+ return this._state.enabled;
872
+ },
873
+
874
+ on: function on(evt, callback) {
875
+ this._bindNonQueryEventHandler(evt, callback);
876
+ return this;
877
+ },
878
+
879
+ off: function off(evt, callback) {
880
+ if ($) {
881
+ this.$element.off(evt, callback);
882
+ this.$sliderElem.off(evt, callback);
883
+ } else {
884
+ this._unbindNonQueryEventHandler(evt, callback);
885
+ }
886
+ },
887
+
888
+ getAttribute: function getAttribute(attribute) {
889
+ if (attribute) {
890
+ return this.options[attribute];
891
+ } else {
892
+ return this.options;
893
+ }
894
+ },
895
+
896
+ setAttribute: function setAttribute(attribute, value) {
897
+ this.options[attribute] = value;
898
+ return this;
899
+ },
900
+
901
+ refresh: function refresh() {
902
+ this._removeSliderEventHandlers();
903
+ createNewSlider.call(this, this.element, this.options);
904
+ if ($) {
905
+ // Bind new instance of slider to the element
906
+ $.data(this.element, 'slider', this);
907
+ }
908
+ return this;
909
+ },
910
+
911
+ relayout: function relayout() {
912
+ this._resize();
913
+ this._layout();
914
+ return this;
915
+ },
916
+
917
+ /******************************+
918
+ HELPERS
919
+ - Any method that is not part of the public interface.
920
+ - Place it underneath this comment block and write its signature like so:
921
+ _fnName : function() {...}
922
+ ********************************/
923
+ _removeSliderEventHandlers: function _removeSliderEventHandlers() {
924
+ // Remove keydown event listeners
925
+ this.handle1.removeEventListener("keydown", this.handle1Keydown, false);
926
+ this.handle2.removeEventListener("keydown", this.handle2Keydown, false);
927
+
928
+ if (this.showTooltip) {
929
+ this.handle1.removeEventListener("focus", this.showTooltip, false);
930
+ this.handle2.removeEventListener("focus", this.showTooltip, false);
931
+ }
932
+ if (this.hideTooltip) {
933
+ this.handle1.removeEventListener("blur", this.hideTooltip, false);
934
+ this.handle2.removeEventListener("blur", this.hideTooltip, false);
935
+ }
936
+
937
+ // Remove event listeners from sliderElem
938
+ if (this.showTooltip) {
939
+ this.sliderElem.removeEventListener("mouseenter", this.showTooltip, false);
940
+ }
941
+ if (this.hideTooltip) {
942
+ this.sliderElem.removeEventListener("mouseleave", this.hideTooltip, false);
943
+ }
944
+ this.sliderElem.removeEventListener("touchstart", this.touchstart, false);
945
+ this.sliderElem.removeEventListener("touchmove", this.touchmove, false);
946
+ this.sliderElem.removeEventListener("mousedown", this.mousedown, false);
947
+
948
+ // Remove window event listener
949
+ window.removeEventListener("resize", this.resize, false);
950
+ },
951
+ _bindNonQueryEventHandler: function _bindNonQueryEventHandler(evt, callback) {
952
+ if (this.eventToCallbackMap[evt] === undefined) {
953
+ this.eventToCallbackMap[evt] = [];
954
+ }
955
+ this.eventToCallbackMap[evt].push(callback);
956
+ },
957
+ _unbindNonQueryEventHandler: function _unbindNonQueryEventHandler(evt, callback) {
958
+ var callbacks = this.eventToCallbackMap[evt];
959
+ if (callbacks !== undefined) {
960
+ for (var i = 0; i < callbacks.length; i++) {
961
+ if (callbacks[i] === callback) {
962
+ callbacks.splice(i, 1);
963
+ break;
964
+ }
965
+ }
966
+ }
967
+ },
968
+ _cleanUpEventCallbacksMap: function _cleanUpEventCallbacksMap() {
969
+ var eventNames = Object.keys(this.eventToCallbackMap);
970
+ for (var i = 0; i < eventNames.length; i++) {
971
+ var eventName = eventNames[i];
972
+ this.eventToCallbackMap[eventName] = null;
973
+ }
974
+ },
975
+ _showTooltip: function _showTooltip() {
976
+ if (this.options.tooltip_split === false) {
977
+ this._addClass(this.tooltip, 'in');
978
+ this.tooltip_min.style.display = 'none';
979
+ this.tooltip_max.style.display = 'none';
980
+ } else {
981
+ this._addClass(this.tooltip_min, 'in');
982
+ this._addClass(this.tooltip_max, 'in');
983
+ this.tooltip.style.display = 'none';
984
+ }
985
+ this._state.over = true;
986
+ },
987
+ _hideTooltip: function _hideTooltip() {
988
+ if (this._state.inDrag === false && this.alwaysShowTooltip !== true) {
989
+ this._removeClass(this.tooltip, 'in');
990
+ this._removeClass(this.tooltip_min, 'in');
991
+ this._removeClass(this.tooltip_max, 'in');
992
+ }
993
+ this._state.over = false;
994
+ },
995
+ _layout: function _layout() {
996
+ var positionPercentages;
997
+
998
+ if (this.options.reversed) {
999
+ positionPercentages = [100 - this._state.percentage[0], this.options.range ? 100 - this._state.percentage[1] : this._state.percentage[1]];
1000
+ } else {
1001
+ positionPercentages = [this._state.percentage[0], this._state.percentage[1]];
1002
+ }
1003
+
1004
+ this.handle1.style[this.stylePos] = positionPercentages[0] + '%';
1005
+ this.handle1.setAttribute('aria-valuenow', this._state.value[0]);
1006
+
1007
+ this.handle2.style[this.stylePos] = positionPercentages[1] + '%';
1008
+ this.handle2.setAttribute('aria-valuenow', this._state.value[1]);
1009
+
1010
+ /* Position ticks and labels */
1011
+ if (Array.isArray(this.options.ticks) && this.options.ticks.length > 0) {
1012
+
1013
+ var styleSize = this.options.orientation === 'vertical' ? 'height' : 'width';
1014
+ var styleMargin = this.options.orientation === 'vertical' ? 'marginTop' : 'marginLeft';
1015
+ var labelSize = this._state.size / (this.options.ticks.length - 1);
1016
+
1017
+ if (this.tickLabelContainer) {
1018
+ var extraMargin = 0;
1019
+ if (this.options.ticks_positions.length === 0) {
1020
+ if (this.options.orientation !== 'vertical') {
1021
+ this.tickLabelContainer.style[styleMargin] = -labelSize / 2 + 'px';
1022
+ }
1023
+
1024
+ extraMargin = this.tickLabelContainer.offsetHeight;
1025
+ } else {
1026
+ /* Chidren are position absolute, calculate height by finding the max offsetHeight of a child */
1027
+ for (i = 0; i < this.tickLabelContainer.childNodes.length; i++) {
1028
+ if (this.tickLabelContainer.childNodes[i].offsetHeight > extraMargin) {
1029
+ extraMargin = this.tickLabelContainer.childNodes[i].offsetHeight;
1030
+ }
1031
+ }
1032
+ }
1033
+ if (this.options.orientation === 'horizontal') {
1034
+ this.sliderElem.style.marginBottom = extraMargin + 'px';
1035
+ }
1036
+ }
1037
+ for (var i = 0; i < this.options.ticks.length; i++) {
1038
+
1039
+ var percentage = this.options.ticks_positions[i] || this._toPercentage(this.options.ticks[i]);
1040
+
1041
+ if (this.options.reversed) {
1042
+ percentage = 100 - percentage;
1043
+ }
1044
+
1045
+ this.ticks[i].style[this.stylePos] = percentage + '%';
1046
+
1047
+ /* Set class labels to denote whether ticks are in the selection */
1048
+ this._removeClass(this.ticks[i], 'in-selection');
1049
+ if (!this.options.range) {
1050
+ if (this.options.selection === 'after' && percentage >= positionPercentages[0]) {
1051
+ this._addClass(this.ticks[i], 'in-selection');
1052
+ } else if (this.options.selection === 'before' && percentage <= positionPercentages[0]) {
1053
+ this._addClass(this.ticks[i], 'in-selection');
1054
+ }
1055
+ } else if (percentage >= positionPercentages[0] && percentage <= positionPercentages[1]) {
1056
+ this._addClass(this.ticks[i], 'in-selection');
1057
+ }
1058
+
1059
+ if (this.tickLabels[i]) {
1060
+ this.tickLabels[i].style[styleSize] = labelSize + 'px';
1061
+
1062
+ if (this.options.orientation !== 'vertical' && this.options.ticks_positions[i] !== undefined) {
1063
+ this.tickLabels[i].style.position = 'absolute';
1064
+ this.tickLabels[i].style[this.stylePos] = percentage + '%';
1065
+ this.tickLabels[i].style[styleMargin] = -labelSize / 2 + 'px';
1066
+ } else if (this.options.orientation === 'vertical') {
1067
+ this.tickLabels[i].style['marginLeft'] = this.sliderElem.offsetWidth + 'px';
1068
+ this.tickLabelContainer.style['marginTop'] = this.sliderElem.offsetWidth / 2 * -1 + 'px';
1069
+ }
1070
+ }
1071
+ }
1072
+ }
1073
+
1074
+ var formattedTooltipVal;
1075
+
1076
+ if (this.options.range) {
1077
+ formattedTooltipVal = this.options.formatter(this._state.value);
1078
+ this._setText(this.tooltipInner, formattedTooltipVal);
1079
+ this.tooltip.style[this.stylePos] = (positionPercentages[1] + positionPercentages[0]) / 2 + '%';
1080
+
1081
+ if (this.options.orientation === 'vertical') {
1082
+ this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1083
+ } else {
1084
+ this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1085
+ }
1086
+
1087
+ if (this.options.orientation === 'vertical') {
1088
+ this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1089
+ } else {
1090
+ this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1091
+ }
1092
+
1093
+ var innerTooltipMinText = this.options.formatter(this._state.value[0]);
1094
+ this._setText(this.tooltipInner_min, innerTooltipMinText);
1095
+
1096
+ var innerTooltipMaxText = this.options.formatter(this._state.value[1]);
1097
+ this._setText(this.tooltipInner_max, innerTooltipMaxText);
1098
+
1099
+ this.tooltip_min.style[this.stylePos] = positionPercentages[0] + '%';
1100
+
1101
+ if (this.options.orientation === 'vertical') {
1102
+ this._css(this.tooltip_min, 'margin-top', -this.tooltip_min.offsetHeight / 2 + 'px');
1103
+ } else {
1104
+ this._css(this.tooltip_min, 'margin-left', -this.tooltip_min.offsetWidth / 2 + 'px');
1105
+ }
1106
+
1107
+ this.tooltip_max.style[this.stylePos] = positionPercentages[1] + '%';
1108
+
1109
+ if (this.options.orientation === 'vertical') {
1110
+ this._css(this.tooltip_max, 'margin-top', -this.tooltip_max.offsetHeight / 2 + 'px');
1111
+ } else {
1112
+ this._css(this.tooltip_max, 'margin-left', -this.tooltip_max.offsetWidth / 2 + 'px');
1113
+ }
1114
+ } else {
1115
+ formattedTooltipVal = this.options.formatter(this._state.value[0]);
1116
+ this._setText(this.tooltipInner, formattedTooltipVal);
1117
+
1118
+ this.tooltip.style[this.stylePos] = positionPercentages[0] + '%';
1119
+ if (this.options.orientation === 'vertical') {
1120
+ this._css(this.tooltip, 'margin-top', -this.tooltip.offsetHeight / 2 + 'px');
1121
+ } else {
1122
+ this._css(this.tooltip, 'margin-left', -this.tooltip.offsetWidth / 2 + 'px');
1123
+ }
1124
+ }
1125
+
1126
+ if (this.options.orientation === 'vertical') {
1127
+ this.trackLow.style.top = '0';
1128
+ this.trackLow.style.height = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
1129
+
1130
+ this.trackSelection.style.top = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
1131
+ this.trackSelection.style.height = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
1132
+
1133
+ this.trackHigh.style.bottom = '0';
1134
+ this.trackHigh.style.height = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
1135
+ } else {
1136
+ this.trackLow.style.left = '0';
1137
+ this.trackLow.style.width = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
1138
+
1139
+ this.trackSelection.style.left = Math.min(positionPercentages[0], positionPercentages[1]) + '%';
1140
+ this.trackSelection.style.width = Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
1141
+
1142
+ this.trackHigh.style.right = '0';
1143
+ this.trackHigh.style.width = 100 - Math.min(positionPercentages[0], positionPercentages[1]) - Math.abs(positionPercentages[0] - positionPercentages[1]) + '%';
1144
+
1145
+ var offset_min = this.tooltip_min.getBoundingClientRect();
1146
+ var offset_max = this.tooltip_max.getBoundingClientRect();
1147
+
1148
+ if (this.options.tooltip_position === 'bottom') {
1149
+ if (offset_min.right > offset_max.left) {
1150
+ this._removeClass(this.tooltip_max, 'bottom');
1151
+ this._addClass(this.tooltip_max, 'top');
1152
+ this.tooltip_max.style.top = '';
1153
+ this.tooltip_max.style.bottom = 22 + 'px';
1154
+ } else {
1155
+ this._removeClass(this.tooltip_max, 'top');
1156
+ this._addClass(this.tooltip_max, 'bottom');
1157
+ this.tooltip_max.style.top = this.tooltip_min.style.top;
1158
+ this.tooltip_max.style.bottom = '';
1159
+ }
1160
+ } else {
1161
+ if (offset_min.right > offset_max.left) {
1162
+ this._removeClass(this.tooltip_max, 'top');
1163
+ this._addClass(this.tooltip_max, 'bottom');
1164
+ this.tooltip_max.style.top = 18 + 'px';
1165
+ } else {
1166
+ this._removeClass(this.tooltip_max, 'bottom');
1167
+ this._addClass(this.tooltip_max, 'top');
1168
+ this.tooltip_max.style.top = this.tooltip_min.style.top;
1169
+ }
1170
+ }
1171
+ }
1172
+ },
1173
+ _resize: function _resize(ev) {
1174
+ /*jshint unused:false*/
1175
+ this._state.offset = this._offset(this.sliderElem);
1176
+ this._state.size = this.sliderElem[this.sizePos];
1177
+ this._layout();
1178
+ },
1179
+ _removeProperty: function _removeProperty(element, prop) {
1180
+ if (element.style.removeProperty) {
1181
+ element.style.removeProperty(prop);
1182
+ } else {
1183
+ element.style.removeAttribute(prop);
1184
+ }
1185
+ },
1186
+ _mousedown: function _mousedown(ev) {
1187
+ if (!this._state.enabled) {
1188
+ return false;
1189
+ }
1190
+
1191
+ this._state.offset = this._offset(this.sliderElem);
1192
+ this._state.size = this.sliderElem[this.sizePos];
1193
+
1194
+ var percentage = this._getPercentage(ev);
1195
+
1196
+ if (this.options.range) {
1197
+ var diff1 = Math.abs(this._state.percentage[0] - percentage);
1198
+ var diff2 = Math.abs(this._state.percentage[1] - percentage);
1199
+ this._state.dragged = diff1 < diff2 ? 0 : 1;
1200
+ this._adjustPercentageForRangeSliders(percentage);
1201
+ } else {
1202
+ this._state.dragged = 0;
1203
+ }
1204
+
1205
+ this._state.percentage[this._state.dragged] = percentage;
1206
+ this._layout();
1207
+
1208
+ if (this.touchCapable) {
1209
+ document.removeEventListener("touchmove", this.mousemove, false);
1210
+ document.removeEventListener("touchend", this.mouseup, false);
1211
+ }
1212
+
1213
+ if (this.mousemove) {
1214
+ document.removeEventListener("mousemove", this.mousemove, false);
1215
+ }
1216
+ if (this.mouseup) {
1217
+ document.removeEventListener("mouseup", this.mouseup, false);
1218
+ }
1219
+
1220
+ this.mousemove = this._mousemove.bind(this);
1221
+ this.mouseup = this._mouseup.bind(this);
1222
+
1223
+ if (this.touchCapable) {
1224
+ // Touch: Bind touch events:
1225
+ document.addEventListener("touchmove", this.mousemove, false);
1226
+ document.addEventListener("touchend", this.mouseup, false);
1227
+ }
1228
+ // Bind mouse events:
1229
+ document.addEventListener("mousemove", this.mousemove, false);
1230
+ document.addEventListener("mouseup", this.mouseup, false);
1231
+
1232
+ this._state.inDrag = true;
1233
+ var newValue = this._calculateValue();
1234
+
1235
+ this._trigger('slideStart', newValue);
1236
+
1237
+ this._setDataVal(newValue);
1238
+ this.setValue(newValue, false, true);
1239
+
1240
+ this._pauseEvent(ev);
1241
+
1242
+ if (this.options.focus) {
1243
+ this._triggerFocusOnHandle(this._state.dragged);
1244
+ }
1245
+
1246
+ return true;
1247
+ },
1248
+ _touchstart: function _touchstart(ev) {
1249
+ if (ev.changedTouches === undefined) {
1250
+ this._mousedown(ev);
1251
+ return;
1252
+ }
1253
+
1254
+ var touch = ev.changedTouches[0];
1255
+ this.touchX = touch.pageX;
1256
+ this.touchY = touch.pageY;
1257
+ },
1258
+ _triggerFocusOnHandle: function _triggerFocusOnHandle(handleIdx) {
1259
+ if (handleIdx === 0) {
1260
+ this.handle1.focus();
1261
+ }
1262
+ if (handleIdx === 1) {
1263
+ this.handle2.focus();
1264
+ }
1265
+ },
1266
+ _keydown: function _keydown(handleIdx, ev) {
1267
+ if (!this._state.enabled) {
1268
+ return false;
1269
+ }
1270
+
1271
+ var dir;
1272
+ switch (ev.keyCode) {
1273
+ case 37: // left
1274
+ case 40:
1275
+ // down
1276
+ dir = -1;
1277
+ break;
1278
+ case 39: // right
1279
+ case 38:
1280
+ // up
1281
+ dir = 1;
1282
+ break;
1283
+ }
1284
+ if (!dir) {
1285
+ return;
1286
+ }
1287
+
1288
+ // use natural arrow keys instead of from min to max
1289
+ if (this.options.natural_arrow_keys) {
1290
+ var ifVerticalAndNotReversed = this.options.orientation === 'vertical' && !this.options.reversed;
1291
+ var ifHorizontalAndReversed = this.options.orientation === 'horizontal' && this.options.reversed;
1292
+
1293
+ if (ifVerticalAndNotReversed || ifHorizontalAndReversed) {
1294
+ dir = -dir;
1295
+ }
1296
+ }
1297
+
1298
+ var val = this._state.value[handleIdx] + dir * this.options.step;
1299
+ if (this.options.range) {
1300
+ val = [!handleIdx ? val : this._state.value[0], handleIdx ? val : this._state.value[1]];
1301
+ }
1302
+
1303
+ this._trigger('slideStart', val);
1304
+ this._setDataVal(val);
1305
+ this.setValue(val, true, true);
1306
+
1307
+ this._setDataVal(val);
1308
+ this._trigger('slideStop', val);
1309
+ this._layout();
1310
+
1311
+ this._pauseEvent(ev);
1312
+
1313
+ return false;
1314
+ },
1315
+ _pauseEvent: function _pauseEvent(ev) {
1316
+ if (ev.stopPropagation) {
1317
+ ev.stopPropagation();
1318
+ }
1319
+ if (ev.preventDefault) {
1320
+ ev.preventDefault();
1321
+ }
1322
+ ev.cancelBubble = true;
1323
+ ev.returnValue = false;
1324
+ },
1325
+ _mousemove: function _mousemove(ev) {
1326
+ if (!this._state.enabled) {
1327
+ return false;
1328
+ }
1329
+
1330
+ var percentage = this._getPercentage(ev);
1331
+ this._adjustPercentageForRangeSliders(percentage);
1332
+ this._state.percentage[this._state.dragged] = percentage;
1333
+ this._layout();
1334
+
1335
+ var val = this._calculateValue(true);
1336
+ this.setValue(val, true, true);
1337
+
1338
+ return false;
1339
+ },
1340
+ _touchmove: function _touchmove(ev) {
1341
+ if (ev.changedTouches === undefined) {
1342
+ return;
1343
+ }
1344
+
1345
+ var touch = ev.changedTouches[0];
1346
+
1347
+ var xDiff = touch.pageX - this.touchX;
1348
+ var yDiff = touch.pageY - this.touchY;
1349
+
1350
+ if (!this._state.inDrag) {
1351
+ // Vertical Slider
1352
+ if (this.options.orientation === 'vertical' && xDiff <= 5 && xDiff >= -5 && (yDiff >= 15 || yDiff <= -15)) {
1353
+ this._mousedown(ev);
1354
+ }
1355
+ // Horizontal slider.
1356
+ else if (yDiff <= 5 && yDiff >= -5 && (xDiff >= 15 || xDiff <= -15)) {
1357
+ this._mousedown(ev);
1358
+ }
1359
+ }
1360
+ },
1361
+ _adjustPercentageForRangeSliders: function _adjustPercentageForRangeSliders(percentage) {
1362
+ if (this.options.range) {
1363
+ var precision = this._getNumDigitsAfterDecimalPlace(percentage);
1364
+ precision = precision ? precision - 1 : 0;
1365
+ var percentageWithAdjustedPrecision = this._applyToFixedAndParseFloat(percentage, precision);
1366
+ if (this._state.dragged === 0 && this._applyToFixedAndParseFloat(this._state.percentage[1], precision) < percentageWithAdjustedPrecision) {
1367
+ this._state.percentage[0] = this._state.percentage[1];
1368
+ this._state.dragged = 1;
1369
+ } else if (this._state.dragged === 1 && this._applyToFixedAndParseFloat(this._state.percentage[0], precision) > percentageWithAdjustedPrecision) {
1370
+ this._state.percentage[1] = this._state.percentage[0];
1371
+ this._state.dragged = 0;
1372
+ }
1373
+ }
1374
+ },
1375
+ _mouseup: function _mouseup() {
1376
+ if (!this._state.enabled) {
1377
+ return false;
1378
+ }
1379
+ if (this.touchCapable) {
1380
+ // Touch: Unbind touch event handlers:
1381
+ document.removeEventListener("touchmove", this.mousemove, false);
1382
+ document.removeEventListener("touchend", this.mouseup, false);
1383
+ }
1384
+ // Unbind mouse event handlers:
1385
+ document.removeEventListener("mousemove", this.mousemove, false);
1386
+ document.removeEventListener("mouseup", this.mouseup, false);
1387
+
1388
+ this._state.inDrag = false;
1389
+ if (this._state.over === false) {
1390
+ this._hideTooltip();
1391
+ }
1392
+ var val = this._calculateValue(true);
1393
+
1394
+ this._layout();
1395
+ this._setDataVal(val);
1396
+ this._trigger('slideStop', val);
1397
+
1398
+ return false;
1399
+ },
1400
+ _calculateValue: function _calculateValue(snapToClosestTick) {
1401
+ var val;
1402
+ if (this.options.range) {
1403
+ val = [this.options.min, this.options.max];
1404
+ if (this._state.percentage[0] !== 0) {
1405
+ val[0] = this._toValue(this._state.percentage[0]);
1406
+ val[0] = this._applyPrecision(val[0]);
1407
+ }
1408
+ if (this._state.percentage[1] !== 100) {
1409
+ val[1] = this._toValue(this._state.percentage[1]);
1410
+ val[1] = this._applyPrecision(val[1]);
1411
+ }
1412
+ } else {
1413
+ val = this._toValue(this._state.percentage[0]);
1414
+ val = parseFloat(val);
1415
+ val = this._applyPrecision(val);
1416
+ }
1417
+
1418
+ if (snapToClosestTick) {
1419
+ var min = [val, Infinity];
1420
+ for (var i = 0; i < this.options.ticks.length; i++) {
1421
+ var diff = Math.abs(this.options.ticks[i] - val);
1422
+ if (diff <= min[1]) {
1423
+ min = [this.options.ticks[i], diff];
1424
+ }
1425
+ }
1426
+ if (min[1] <= this.options.ticks_snap_bounds) {
1427
+ return min[0];
1428
+ }
1429
+ }
1430
+
1431
+ return val;
1432
+ },
1433
+ _applyPrecision: function _applyPrecision(val) {
1434
+ var precision = this.options.precision || this._getNumDigitsAfterDecimalPlace(this.options.step);
1435
+ return this._applyToFixedAndParseFloat(val, precision);
1436
+ },
1437
+ _getNumDigitsAfterDecimalPlace: function _getNumDigitsAfterDecimalPlace(num) {
1438
+ var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
1439
+ if (!match) {
1440
+ return 0;
1441
+ }
1442
+ return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
1443
+ },
1444
+ _applyToFixedAndParseFloat: function _applyToFixedAndParseFloat(num, toFixedInput) {
1445
+ var truncatedNum = num.toFixed(toFixedInput);
1446
+ return parseFloat(truncatedNum);
1447
+ },
1448
+ /*
1449
+ Credits to Mike Samuel for the following method!
1450
+ Source: http://stackoverflow.com/questions/10454518/javascript-how-to-retrieve-the-number-of-decimals-of-a-string-number
1451
+ */
1452
+ _getPercentage: function _getPercentage(ev) {
1453
+ if (this.touchCapable && (ev.type === 'touchstart' || ev.type === 'touchmove')) {
1454
+ ev = ev.touches[0];
1455
+ }
1456
+
1457
+ var eventPosition = ev[this.mousePos];
1458
+ var sliderOffset = this._state.offset[this.stylePos];
1459
+ var distanceToSlide = eventPosition - sliderOffset;
1460
+ // Calculate what percent of the length the slider handle has slid
1461
+ var percentage = distanceToSlide / this._state.size * 100;
1462
+ percentage = Math.round(percentage / this._state.percentage[2]) * this._state.percentage[2];
1463
+ if (this.options.reversed) {
1464
+ percentage = 100 - percentage;
1465
+ }
1466
+
1467
+ // Make sure the percent is within the bounds of the slider.
1468
+ // 0% corresponds to the 'min' value of the slide
1469
+ // 100% corresponds to the 'max' value of the slide
1470
+ return Math.max(0, Math.min(100, percentage));
1471
+ },
1472
+ _validateInputValue: function _validateInputValue(val) {
1473
+ if (typeof val === 'number') {
1474
+ return val;
1475
+ } else if (Array.isArray(val)) {
1476
+ this._validateArray(val);
1477
+ return val;
1478
+ } else {
1479
+ throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(val));
1480
+ }
1481
+ },
1482
+ _validateArray: function _validateArray(val) {
1483
+ for (var i = 0; i < val.length; i++) {
1484
+ var input = val[i];
1485
+ if (typeof input !== 'number') {
1486
+ throw new Error(ErrorMsgs.formatInvalidInputErrorMsg(input));
1487
+ }
1488
+ }
1489
+ },
1490
+ _setDataVal: function _setDataVal(val) {
1491
+ this.element.setAttribute('data-value', val);
1492
+ this.element.setAttribute('value', val);
1493
+ this.element.value = val;
1494
+ },
1495
+ _trigger: function _trigger(evt, val) {
1496
+ val = val || val === 0 ? val : undefined;
1497
+
1498
+ var callbackFnArray = this.eventToCallbackMap[evt];
1499
+ if (callbackFnArray && callbackFnArray.length) {
1500
+ for (var i = 0; i < callbackFnArray.length; i++) {
1501
+ var callbackFn = callbackFnArray[i];
1502
+ callbackFn(val);
1503
+ }
1504
+ }
1505
+
1506
+ /* If JQuery exists, trigger JQuery events */
1507
+ if ($) {
1508
+ this._triggerJQueryEvent(evt, val);
1509
+ }
1510
+ },
1511
+ _triggerJQueryEvent: function _triggerJQueryEvent(evt, val) {
1512
+ var eventData = {
1513
+ type: evt,
1514
+ value: val
1515
+ };
1516
+ this.$element.trigger(eventData);
1517
+ this.$sliderElem.trigger(eventData);
1518
+ },
1519
+ _unbindJQueryEventHandlers: function _unbindJQueryEventHandlers() {
1520
+ this.$element.off();
1521
+ this.$sliderElem.off();
1522
+ },
1523
+ _setText: function _setText(element, text) {
1524
+ if (typeof element.textContent !== "undefined") {
1525
+ element.textContent = text;
1526
+ } else if (typeof element.innerText !== "undefined") {
1527
+ element.innerText = text;
1528
+ }
1529
+ },
1530
+ _removeClass: function _removeClass(element, classString) {
1531
+ var classes = classString.split(" ");
1532
+ var newClasses = element.className;
1533
+
1534
+ for (var i = 0; i < classes.length; i++) {
1535
+ var classTag = classes[i];
1536
+ var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
1537
+ newClasses = newClasses.replace(regex, " ");
1538
+ }
1539
+
1540
+ element.className = newClasses.trim();
1541
+ },
1542
+ _addClass: function _addClass(element, classString) {
1543
+ var classes = classString.split(" ");
1544
+ var newClasses = element.className;
1545
+
1546
+ for (var i = 0; i < classes.length; i++) {
1547
+ var classTag = classes[i];
1548
+ var regex = new RegExp("(?:\\s|^)" + classTag + "(?:\\s|$)");
1549
+ var ifClassExists = regex.test(newClasses);
1550
+
1551
+ if (!ifClassExists) {
1552
+ newClasses += " " + classTag;
1553
+ }
1554
+ }
1555
+
1556
+ element.className = newClasses.trim();
1557
+ },
1558
+ _offsetLeft: function _offsetLeft(obj) {
1559
+ return obj.getBoundingClientRect().left;
1560
+ },
1561
+ _offsetTop: function _offsetTop(obj) {
1562
+ var offsetTop = obj.offsetTop;
1563
+ while ((obj = obj.offsetParent) && !isNaN(obj.offsetTop)) {
1564
+ offsetTop += obj.offsetTop;
1565
+ if (obj.tagName !== 'BODY') {
1566
+ offsetTop -= obj.scrollTop;
1567
+ }
1568
+ }
1569
+ return offsetTop;
1570
+ },
1571
+ _offset: function _offset(obj) {
1572
+ return {
1573
+ left: this._offsetLeft(obj),
1574
+ top: this._offsetTop(obj)
1575
+ };
1576
+ },
1577
+ _css: function _css(elementRef, styleName, value) {
1578
+ if ($) {
1579
+ $.style(elementRef, styleName, value);
1580
+ } else {
1581
+ var style = styleName.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi, function (all, letter) {
1582
+ return letter.toUpperCase();
1583
+ });
1584
+ elementRef.style[style] = value;
1585
+ }
1586
+ },
1587
+ _toValue: function _toValue(percentage) {
1588
+ return this.options.scale.toValue.apply(this, [percentage]);
1589
+ },
1590
+ _toPercentage: function _toPercentage(value) {
1591
+ return this.options.scale.toPercentage.apply(this, [value]);
1592
+ },
1593
+ _setTooltipPosition: function _setTooltipPosition() {
1594
+ var tooltips = [this.tooltip, this.tooltip_min, this.tooltip_max];
1595
+ if (this.options.orientation === 'vertical') {
1596
+ var tooltipPos = this.options.tooltip_position || 'right';
1597
+ var oppositeSide = tooltipPos === 'left' ? 'right' : 'left';
1598
+ tooltips.forEach((function (tooltip) {
1599
+ this._addClass(tooltip, tooltipPos);
1600
+ tooltip.style[oppositeSide] = '100%';
1601
+ }).bind(this));
1602
+ } else if (this.options.tooltip_position === 'bottom') {
1603
+ tooltips.forEach((function (tooltip) {
1604
+ this._addClass(tooltip, 'bottom');
1605
+ tooltip.style.top = 22 + 'px';
1606
+ }).bind(this));
1607
+ } else {
1608
+ tooltips.forEach((function (tooltip) {
1609
+ this._addClass(tooltip, 'top');
1610
+ tooltip.style.top = -this.tooltip.outerHeight - 14 + 'px';
1611
+ }).bind(this));
1612
+ }
1613
+ }
1614
+ };
1615
+
1616
+ /*********************************
1617
+ Attach to global namespace
1618
+ *********************************/
1619
+ if ($) {
1620
+ (function () {
1621
+ var autoRegisterNamespace = undefined;
1622
+
1623
+ if (!$.fn.slider) {
1624
+ $.bridget(NAMESPACE_MAIN, Slider);
1625
+ autoRegisterNamespace = NAMESPACE_MAIN;
1626
+ } else {
1627
+ window.console.warn("bootstrap-slider.js - WARNING: $.fn.slider namespace is already bound. Use the $.fn.bootstrapSlider namespace instead.");
1628
+ autoRegisterNamespace = NAMESPACE_ALTERNATE;
1629
+ }
1630
+ $.bridget(NAMESPACE_ALTERNATE, Slider);
1631
+
1632
+ // Auto-Register data-provide="slider" Elements
1633
+ $(function () {
1634
+ $("input[data-provide=slider]")[autoRegisterNamespace]();
1635
+ });
1636
+ })();
1637
+ }
1638
+ })($);
1639
+
1640
+ return Slider;
1641
+ });