Skip to content

Commit 38d88e7

Browse files
committed
dist
1 parent c3aef22 commit 38d88e7

4 files changed

+61
-27
lines changed

dist/jquery.radioslider.js

+34-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
defaults = {
1313
size: '', // General slider size
1414
animation: true, // Enable fill animation
15-
isDisabled: false, // Make the inputs disabled
15+
isDisabledd: false, // Make the inputs disabled
1616
fillOffset: null, // Offset the fill center
1717
fillOrigin: null, // Make the fill bidirectional
1818
fit: false, // Fit the edges
@@ -29,13 +29,13 @@
2929
handleClass: 'radioslider__handle',
3030
horizontalClass: 'radioslider_horizontal',
3131
verticalClass: 'radioslider_vertical',
32-
disabledClass: 'radioslider_disabled',
3332
fitClass: 'radioslider_fit',
3433
animationClass: 'radioslider_animated',
3534
dotUnderClass: 'under',
3635
inverseClass: 'inverse',
3736
activeClass: 'active',
3837
focusClass: 'focused',
38+
disabledClass: 'disabled',
3939
},
4040
constants = {
4141
orientation: {
@@ -62,10 +62,10 @@
6262
function Plugin(element, options) {
6363
pluginNumber++;
6464

65-
this.options = $.extend( {}, defaults, options );
6665
this.$window = $(window);
6766
this.$document = $(document);
6867
this.$bearer = $(element);
68+
this.options = $.extend( {}, defaults, options, this.$bearer.data() );
6969
this.orientation = this.options.orientation;
7070
this.DIMENSION = constants.orientation[this.orientation].dimension;
7171
this.DIRECTION = constants.orientation[this.orientation].direction;
@@ -102,7 +102,7 @@
102102
this.addBase();
103103
this.setSlider();
104104
this.addInteraction();
105-
if (this.options.isDisabled) {
105+
if (this.options.isDisabledd) {
106106
this.setDisabled();
107107
}
108108
};
@@ -129,6 +129,7 @@
129129
.attr('data-radioslider', this.number);
130130

131131
// Inputs : add class and level data
132+
// Store the initial disabled inputs
132133
$inputs = $bearer
133134
.find('> input[type=radio]')
134135
.each(function(i) {
@@ -137,6 +138,7 @@
137138
.attr('data-level', i+1);
138139
});
139140
this.$inputs = $inputs;
141+
this.$inputsDisabled = this.$bearer.find('> input[type=radio][disabled]');
140142

141143
// Labels : add class and level data, insert dots, wrap text
142144
$labels = $bearer
@@ -173,9 +175,14 @@
173175
.nextUntil('input')
174176
.addBack()
175177
.wrapAll($item);
178+
// Add disabled class
179+
if ($(this).attr('disabled') === 'disabled') {
180+
$(this).parent().addClass(options.disabledClass);
181+
}
176182
});
177183
$items = $bearer.find('.' + options.itemClass);
178184
this.$items = $items;
185+
// If vertical, inverse order
179186
if (this.orientation === 'vertical') {
180187
$items.each(function(i, el){
181188
$bearer.prepend(el);
@@ -212,6 +219,10 @@
212219
fillDirection,
213220
input;
214221

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+
215226
// Get elements dimensions
216227
currentLevel = Number($inputChecked.attr('data-level'));
217228
currentValue = this.getValueFromLevel(currentLevel);
@@ -351,19 +362,22 @@
351362

352363
// Disable the slider
353364
Plugin.prototype.setDisabled = function(callback) {
354-
this.options.isDisable = true;
365+
this.options.isDisabled = true;
355366

356367
var slider = this,
357368
$bearer = slider.$bearer,
358369
$labels = slider.$labels,
359370
$inputs = slider.$inputs,
360371
disabledClass = slider.options.disabledClass;
361372

373+
// Add disabled attribute and cancel click and change events
362374
$.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);
367381
});
368382

369383
if (typeof callback === 'function') {
@@ -377,26 +391,31 @@
377391

378392
// Enable the slider
379393
Plugin.prototype.setEnabled = function(callback) {
380-
this.options.isDisable = false;
394+
this.options.isDisabled = false;
381395

382396
var slider = this,
383397
$bearer = slider.$bearer,
384398
$labels = slider.$labels,
385399
$inputs = slider.$inputs,
386400
disabledClass = slider.options.disabledClass;
387401

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);
391407
});
392408

409+
// Add interaction back
410+
slider.addInteraction();
411+
393412
if (typeof callback === 'function') {
394413
callback($labels, $inputs);
395414
}
396415

397416
$bearer
398-
.removeClass(disabledClass)
399-
.trigger('radiodenabled', { origin: this.identifier });
417+
.trigger('radiodenabled', { origin: this.identifier })
418+
.removeClass(disabledClass);
400419
};
401420

402421
// Get current value

0 commit comments

Comments
 (0)