PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / public / js / wdk-slider-range.js

wdk-slider-range.js in WP Directory Kit 1.5.9, at public/js/wdk-slider-range.js

246 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 var $slider = this.self.find('.wdk-slider-range-input');
183
184 $slider.ionRangeSlider({
185 skin: "round",
186 type: "double",
187 grid: true,
188 min: that.options.min,
189 max: that.options.max,
190 from: that.options.predifinedMin,
191 to: that.options.predifinedMax,
192 prefix: that.options.prefix,
193 postfix: that.options.sufix,
194 max_postfix: "+",
195 step: this.step,
196 decorate_both: true,
197 values_separator: '-',
198 onChange: function (data) {
199
200 that.self.find('.value-min').val(data.from);
201 that.self.find('.value-max').val(data.to);
202
203 if(data.max == data.to)
204 that.self.find('.value-max').val('');
205
206 if(data.min == data.from)
207 that.self.find('.value-min').val('');
208 },
209 });
210
211 // save instance
212 this.slider = $slider.data("ionRangeSlider");
213
214 },
215
216 reset: function () {
217
218 if(!this.slider)
219 return;
220
221 this.slider.reset();
222
223 this.self.find('.value-min').val('');
224 this.self.find('.value-max').val('');
225 },
226
227 /**
228 * Remove slider instance
229 * and unbind all events
230 */
231 remove: function () {
232 this.remove();
233 }
234
235 };
236
237 $.fn.fieldSliderRange = function (options) {
238 return this.each(function() {
239 if (!$.data(this, "fieldSliderRange")) {
240 $.data(this, "fieldSliderRange", new FieldSliderRange(this, options, plugin_count++));
241 }
242 });
243 };
244
245 }));
246