| 1 |
// Field slider range |
| 2 |
// © Denis Ineshin, 2019 |
| 3 |
// |
| 4 |
// Project page: http://ionden.com/a/plugins/ion.rangeSlider/en.html |
| 5 |
// GitHub page: https://github.com/IonDen/ion.rangeSlider |
| 6 |
// |
| 7 |
// Released under MIT licence: |
| 8 |
// http://ionden.com/a/plugins/licence-en.html |
| 9 |
// ===================================================================================================================== |
| 10 |
|
| 11 |
;(function(factory) { |
| 12 |
if ((typeof jQuery === 'undefined' || !jQuery) && typeof define === "function" && define.amd) { |
| 13 |
define(["jquery"], function (jQuery) { |
| 14 |
return factory(jQuery, document, window, navigator); |
| 15 |
}); |
| 16 |
} else if ((typeof jQuery === 'undefined' || !jQuery) && typeof exports === "object") { |
| 17 |
factory(require("jquery"), document, window, navigator); |
| 18 |
} else { |
| 19 |
factory(jQuery, document, window, navigator); |
| 20 |
} |
| 21 |
} (function ($, document, window, navigator, undefined) { |
| 22 |
"use strict"; |
| 23 |
|
| 24 |
// ================================================================================================================= |
| 25 |
// Service |
| 26 |
|
| 27 |
var plugin_count = 0; |
| 28 |
|
| 29 |
if (!Function.prototype.bind) { |
| 30 |
Function.prototype.bind = function bind(that) { |
| 31 |
|
| 32 |
var target = this; |
| 33 |
var slice = [].slice; |
| 34 |
|
| 35 |
if (typeof target != "function") { |
| 36 |
throw new TypeError(); |
| 37 |
} |
| 38 |
|
| 39 |
var args = slice.call(arguments, 1), |
| 40 |
bound = function () { |
| 41 |
|
| 42 |
if (this instanceof bound) { |
| 43 |
|
| 44 |
var F = function(){}; |
| 45 |
F.prototype = target.prototype; |
| 46 |
var self = new F(); |
| 47 |
|
| 48 |
var result = target.apply( |
| 49 |
self, |
| 50 |
args.concat(slice.call(arguments)) |
| 51 |
); |
| 52 |
if (Object(result) === result) { |
| 53 |
return result; |
| 54 |
} |
| 55 |
return self; |
| 56 |
|
| 57 |
} else { |
| 58 |
|
| 59 |
return target.apply( |
| 60 |
that, |
| 61 |
args.concat(slice.call(arguments)) |
| 62 |
); |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
}; |
| 67 |
|
| 68 |
return bound; |
| 69 |
}; |
| 70 |
} |
| 71 |
if (!Array.prototype.indexOf) { |
| 72 |
Array.prototype.indexOf = function(searchElement, fromIndex) { |
| 73 |
var k; |
| 74 |
if (this == null) { |
| 75 |
throw new TypeError('"this" is null or not defined'); |
| 76 |
} |
| 77 |
var O = Object(this); |
| 78 |
var len = O.length >>> 0; |
| 79 |
if (len === 0) { |
| 80 |
return -1; |
| 81 |
} |
| 82 |
var n = +fromIndex || 0; |
| 83 |
if (Math.abs(n) === Infinity) { |
| 84 |
n = 0; |
| 85 |
} |
| 86 |
if (n >= len) { |
| 87 |
return -1; |
| 88 |
} |
| 89 |
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); |
| 90 |
while (k < len) { |
| 91 |
if (k in O && O[k] === searchElement) { |
| 92 |
return k; |
| 93 |
} |
| 94 |
k++; |
| 95 |
} |
| 96 |
return -1; |
| 97 |
}; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
// ================================================================================================================= |
| 103 |
// Template |
| 104 |
|
| 105 |
|
| 106 |
// ================================================================================================================= |
| 107 |
// Core |
| 108 |
|
| 109 |
/** |
| 110 |
* Main plugin constructor |
| 111 |
* |
| 112 |
* @param input {Object} link to base input element |
| 113 |
* @param options {Object} slider config |
| 114 |
* @param plugin_count {Number} |
| 115 |
* @constructor |
| 116 |
*/ |
| 117 |
var FieldSliderRange = function (input, options, plugin_count) { |
| 118 |
this.VERSION = "1"; |
| 119 |
this.input = input; |
| 120 |
this.plugin_count = plugin_count; |
| 121 |
this.value_min = ''; |
| 122 |
this.value_max = ''; |
| 123 |
this.infinity = false; |
| 124 |
this.plugin_count = plugin_count; |
| 125 |
this.step = 1; |
| 126 |
this.self = $(input) ; |
| 127 |
|
| 128 |
this.is_key = false; |
| 129 |
this.is_update = false; |
| 130 |
this.is_start = true; |
| 131 |
this.is_finish = false; |
| 132 |
this.is_active = false; |
| 133 |
this.is_resize = false; |
| 134 |
this.is_click = false; |
| 135 |
var conf_data = this.self.find('.config-range') || ''; |
| 136 |
var config; |
| 137 |
if(conf_data) |
| 138 |
var config = { |
| 139 |
'min' : conf_data.attr('data-min') || '', |
| 140 |
'max' : conf_data.attr('data-max') || '', |
| 141 |
'sufix' : conf_data.attr('data-sufix') || '', |
| 142 |
'prefix' : conf_data.attr('data-prefix') || '', |
| 143 |
'infinity' : conf_data.attr('data-infinity') || 'false', |
| 144 |
'predifinedMin' : conf_data.attr('data-predifinedMin') || '', |
| 145 |
'predifinedMax' : conf_data.attr('data-predifinedMax') || '', |
| 146 |
'onChange' : '' |
| 147 |
|
| 148 |
} |
| 149 |
options = options || {}; |
| 150 |
|
| 151 |
// js config extends default config |
| 152 |
$.extend(config, options); |
| 153 |
|
| 154 |
this.options = config; |
| 155 |
|
| 156 |
// validate config, to be sure that all data types are correct |
| 157 |
this.update_check = {}; |
| 158 |
|
| 159 |
this.init(); |
| 160 |
}; |
| 161 |
|
| 162 |
FieldSliderRange.prototype = { |
| 163 |
/** |
| 164 |
* Starts or updates the plugin instance |
| 165 |
* |
| 166 |
* @param [is_update] {boolean} |
| 167 |
*/ |
| 168 |
init: function (is_update) { |
| 169 |
var that = this; |
| 170 |
|
| 171 |
if(that.options.predifinedMax == '') |
| 172 |
that.options.predifinedMax=that.options.max; |
| 173 |
|
| 174 |
if(that.options.max.length > 6) { |
| 175 |
this.step = 10000; |
| 176 |
}else if(that.options.max.length > 4) { |
| 177 |
this.step = 100; |
| 178 |
}else if(that.options.max.length > 3) { |
| 179 |
this.step = 10; |
| 180 |
} |
| 181 |
|
| 182 |
this.self.find('.wdk-slider-range-input').ionRangeSlider({ |
| 183 |
skin: "round", |
| 184 |
type: "double", |
| 185 |
grid: true, |
| 186 |
min: that.options.min, |
| 187 |
max: that.options.max, |
| 188 |
from: that.options.predifinedMin, |
| 189 |
to: that.options.predifinedMax, |
| 190 |
prefix: that.options.prefix, |
| 191 |
postfix: that.options.sufix, |
| 192 |
max_postfix: "+", |
| 193 |
step: this.step, |
| 194 |
decorate_both: true, |
| 195 |
values_separator: '-', |
| 196 |
onChange: function (data) { |
| 197 |
that.options.onChange; |
| 198 |
that.self.find('.value-min').val(data.from); |
| 199 |
that.self.find('.value-max').val(data.to); |
| 200 |
if(data.max==data.to) |
| 201 |
that.self.find('.value-max').val(''); |
| 202 |
|
| 203 |
if(data.min==data.from) |
| 204 |
that.self.find('.value-min').val(''); |
| 205 |
}, |
| 206 |
}); |
| 207 |
|
| 208 |
}, |
| 209 |
|
| 210 |
/** |
| 211 |
* Remove slider instance |
| 212 |
* and unbind all events |
| 213 |
*/ |
| 214 |
remove: function () { |
| 215 |
this.remove(); |
| 216 |
} |
| 217 |
|
| 218 |
}; |
| 219 |
|
| 220 |
$.fn.fieldSliderRange = function (options) { |
| 221 |
return this.each(function() { |
| 222 |
if (!$.data(this, "fieldSliderRange")) { |
| 223 |
$.data(this, "fieldSliderRange", new FieldSliderRange(this, options, plugin_count++)); |
| 224 |
} |
| 225 |
}); |
| 226 |
}; |
| 227 |
|
| 228 |
})); |
| 229 |
|