|
12 | 12 | defaults = {
|
13 | 13 | size: '', // General slider size
|
14 | 14 | animation: true, // Enable fill animation
|
15 |
| - isDisabled: false, // Make the inputs disabled |
| 15 | + isDisabledd: false, // Make the inputs disabled |
16 | 16 | fillOffset: null, // Offset the fill center
|
17 | 17 | fillOrigin: null, // Make the fill bidirectional
|
18 | 18 | fit: false, // Fit the edges
|
|
29 | 29 | handleClass: 'radioslider__handle',
|
30 | 30 | horizontalClass: 'radioslider_horizontal',
|
31 | 31 | verticalClass: 'radioslider_vertical',
|
32 |
| - disabledClass: 'radioslider_disabled', |
33 | 32 | fitClass: 'radioslider_fit',
|
34 | 33 | animationClass: 'radioslider_animated',
|
35 | 34 | dotUnderClass: 'under',
|
36 | 35 | inverseClass: 'inverse',
|
37 | 36 | activeClass: 'active',
|
38 | 37 | focusClass: 'focused',
|
| 38 | + disabledClass: 'disabled', |
39 | 39 | },
|
40 | 40 | constants = {
|
41 | 41 | orientation: {
|
|
62 | 62 | function Plugin(element, options) {
|
63 | 63 | pluginNumber++;
|
64 | 64 |
|
65 |
| - this.options = $.extend( {}, defaults, options ); |
66 | 65 | this.$window = $(window);
|
67 | 66 | this.$document = $(document);
|
68 | 67 | this.$bearer = $(element);
|
| 68 | + this.options = $.extend( {}, defaults, options, this.$bearer.data() ); |
69 | 69 | this.orientation = this.options.orientation;
|
70 | 70 | this.DIMENSION = constants.orientation[this.orientation].dimension;
|
71 | 71 | this.DIRECTION = constants.orientation[this.orientation].direction;
|
|
102 | 102 | this.addBase();
|
103 | 103 | this.setSlider();
|
104 | 104 | this.addInteraction();
|
105 |
| - if (this.options.isDisabled) { |
| 105 | + if (this.options.isDisabledd) { |
106 | 106 | this.setDisabled();
|
107 | 107 | }
|
108 | 108 | };
|
|
129 | 129 | .attr('data-radioslider', this.number);
|
130 | 130 |
|
131 | 131 | // Inputs : add class and level data
|
| 132 | + // Store the initial disabled inputs |
132 | 133 | $inputs = $bearer
|
133 | 134 | .find('> input[type=radio]')
|
134 | 135 | .each(function(i) {
|
|
137 | 138 | .attr('data-level', i+1);
|
138 | 139 | });
|
139 | 140 | this.$inputs = $inputs;
|
| 141 | + this.$inputsDisabled = this.$bearer.find('> input[type=radio][disabled]'); |
140 | 142 |
|
141 | 143 | // Labels : add class and level data, insert dots, wrap text
|
142 | 144 | $labels = $bearer
|
|
173 | 175 | .nextUntil('input')
|
174 | 176 | .addBack()
|
175 | 177 | .wrapAll($item);
|
| 178 | + // Add disabled class |
| 179 | + if ($(this).attr('disabled') === 'disabled') { |
| 180 | + $(this).parent().addClass(options.disabledClass); |
| 181 | + } |
176 | 182 | });
|
177 | 183 | $items = $bearer.find('.' + options.itemClass);
|
178 | 184 | this.$items = $items;
|
| 185 | + // If vertical, inverse order |
179 | 186 | if (this.orientation === 'vertical') {
|
180 | 187 | $items.each(function(i, el){
|
181 | 188 | $bearer.prepend(el);
|
|
212 | 219 | fillDirection,
|
213 | 220 | input;
|
214 | 221 |
|
| 222 | + // Put active class |
| 223 | + $inputChecked.next('.'+options.labelClass).addClass(options.activeClass).parents('.'+options.itemClass).addClass(options.activeClass); |
| 224 | + $inputs.not($inputChecked).next('.'+options.labelClass).removeClass(options.activeClass).parents('.'+options.itemClass).removeClass(options.activeClass); |
| 225 | + |
215 | 226 | // Get elements dimensions
|
216 | 227 | currentLevel = Number($inputChecked.attr('data-level'));
|
217 | 228 | currentValue = this.getValueFromLevel(currentLevel);
|
|
351 | 362 |
|
352 | 363 | // Disable the slider
|
353 | 364 | Plugin.prototype.setDisabled = function(callback) {
|
354 |
| - this.options.isDisable = true; |
| 365 | + this.options.isDisabled = true; |
355 | 366 |
|
356 | 367 | var slider = this,
|
357 | 368 | $bearer = slider.$bearer,
|
358 | 369 | $labels = slider.$labels,
|
359 | 370 | $inputs = slider.$inputs,
|
360 | 371 | disabledClass = slider.options.disabledClass;
|
361 | 372 |
|
| 373 | + // Add disabled attribute and cancel click and change events |
362 | 374 | $.merge($labels, $inputs).each(function() {
|
363 |
| - var $this = $(this); |
364 |
| - |
365 |
| - $this.prop('disabled', true); |
366 |
| - $this.off('click change'); |
| 375 | + $(this).off('click change'); |
| 376 | + }); |
| 377 | + $inputs.each(function() { |
| 378 | + $(this) |
| 379 | + .prop('disabled', true) |
| 380 | + .parent().addClass(disabledClass); |
367 | 381 | });
|
368 | 382 |
|
369 | 383 | if (typeof callback === 'function') {
|
|
377 | 391 |
|
378 | 392 | // Enable the slider
|
379 | 393 | Plugin.prototype.setEnabled = function(callback) {
|
380 |
| - this.options.isDisable = false; |
| 394 | + this.options.isDisabled = false; |
381 | 395 |
|
382 | 396 | var slider = this,
|
383 | 397 | $bearer = slider.$bearer,
|
384 | 398 | $labels = slider.$labels,
|
385 | 399 | $inputs = slider.$inputs,
|
386 | 400 | disabledClass = slider.options.disabledClass;
|
387 | 401 |
|
388 |
| - $.merge($labels, $inputs).each(function() { |
389 |
| - $(this).prop('disabled', false); |
390 |
| - slider.addInteraction(); |
| 402 | + // Remove the disabled attribute except those which were already here on init |
| 403 | + $inputs.not(slider.$inputsDisabled).each(function() { |
| 404 | + $(this) |
| 405 | + .prop('disabled', false) |
| 406 | + .parent().removeClass(disabledClass); |
391 | 407 | });
|
392 | 408 |
|
| 409 | + // Add interaction back |
| 410 | + slider.addInteraction(); |
| 411 | + |
393 | 412 | if (typeof callback === 'function') {
|
394 | 413 | callback($labels, $inputs);
|
395 | 414 | }
|
396 | 415 |
|
397 | 416 | $bearer
|
398 |
| - .removeClass(disabledClass) |
399 |
| - .trigger('radiodenabled', { origin: this.identifier }); |
| 417 | + .trigger('radiodenabled', { origin: this.identifier }) |
| 418 | + .removeClass(disabledClass); |
400 | 419 | };
|
401 | 420 |
|
402 | 421 | // Get current value
|
|
0 commit comments