Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
fix: set initial value if no value attribute is set
Browse files Browse the repository at this point in the history
  • Loading branch information
andreruffert committed Nov 15, 2015
1 parent 9c1b171 commit 3f5c475
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
8 changes: 2 additions & 6 deletions dist/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,6 @@
Plugin.prototype.init = function() {
this.update(true, false);

// Set initial value just in case it is not set already.
// Prevents trouble if we call `update(true)`
this.$element[0].value = this.value;

if (this.onInit && typeof this.onInit === 'function') {
this.onInit();
}
Expand All @@ -294,7 +290,7 @@
if (updateAttributes) {
this.min = tryParseFloat(this.$element[0].getAttribute('min'), 0);
this.max = tryParseFloat(this.$element[0].getAttribute('max'), 100);
this.value = tryParseFloat(this.$element[0].value, this.min + (this.max-this.min)/2);
this.value = tryParseFloat(this.$element[0].value, Math.round(this.min + (this.max-this.min)/2));
this.step = tryParseFloat(this.$element[0].getAttribute('step'), 1);
}

Expand Down Expand Up @@ -433,7 +429,7 @@
};

Plugin.prototype.setValue = function(value) {
if (value === this.value) {
if (value === this.value && this.$element[0].value !== '') {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/rangeslider.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions src/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@
Plugin.prototype.init = function() {
this.update(true, false);

// Set initial value just in case it is not set already.
// Prevents trouble if we call `update(true)`
this.$element[0].value = this.value;

if (this.onInit && typeof this.onInit === 'function') {
this.onInit();
}
Expand All @@ -293,7 +289,7 @@
if (updateAttributes) {
this.min = tryParseFloat(this.$element[0].getAttribute('min'), 0);
this.max = tryParseFloat(this.$element[0].getAttribute('max'), 100);
this.value = tryParseFloat(this.$element[0].value, this.min + (this.max-this.min)/2);
this.value = tryParseFloat(this.$element[0].value, Math.round(this.min + (this.max-this.min)/2));
this.step = tryParseFloat(this.$element[0].getAttribute('step'), 1);
}

Expand Down Expand Up @@ -432,7 +428,7 @@
};

Plugin.prototype.setValue = function(value) {
if (value === this.value) {
if (value === this.value && this.$element[0].value !== '') {
return;
}

Expand Down

0 comments on commit 3f5c475

Please sign in to comment.