Skip to content

Commit

Permalink
- use number ~ number instead of number to number for input value.
Browse files Browse the repository at this point in the history
 - duse default value `0` for input value if parseFloat fails.
  • Loading branch information
zbryikt committed Jun 2, 2021
1 parent 6604b48 commit 783b268
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## v2.0.3

- use `number ~ number` instead of `number to number` for input value.
- duse default value `0` for input value if parseFloat fails.


## v2.0.2

- handle right-click issue
Expand Down
20 changes: 15 additions & 5 deletions dist/ldrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@ ldSlider = function(opt){
handle = function(){
var v;
if (this$.range) {
v = (this$.input.value || '').split(/\s+to\s+/);
v = (this$.input.value || '').split(/\s*~\s*/);
v = {
from: parseFloat(v[0]),
to: parseFloat(v[1])
from: parseFloat((v[0] || '').trim()),
to: parseFloat((v[1] || '').trim())
};
if (isNaN(v.from)) {
v.from = 0;
}
if (isNaN(v.to)) {
v.from = 0;
}
this$.repos(v.from, true, false, true, false);
return this$.repos(v.to, true, false, true, true);
} else {
return this$.repos(this$.input.value, true, false, true);
v = parseFloat((this$.input.value || '').trim());
if (isNaN(v)) {
v = 0;
}
return this$.repos(v, true, false, true);
}
};
this.input.addEventListener('change', handle);
Expand Down Expand Up @@ -127,7 +137,7 @@ ldSlider.prototype = import$(Object.create(Object.prototype), {
return this.debounce = setTimeout(function(){
var v;
if (this$.range) {
v = this$.val.from + " to " + this$.val.to;
v = this$.val.from + " ~ " + this$.val.to;
if (this$.input.value !== v) {
return this$.input.value = v;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/ldrs.min.js

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

2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "ldslider",
"license": "MIT",
"description": "Slider Library in Vanilla JS",
"version": "2.0.2",
"version": "2.0.3",
"files": [
"dist/**/*"
],
Expand Down
13 changes: 9 additions & 4 deletions src/ldrs.ls
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ ldSlider = (opt={}) ->
if @input.getAttribute(\data-class) => @input.classList.add.apply @input.classList, that.split(' ')
handle = ~>
if @range =>
v = (@input.value or '').split(/\s+to\s+/)
v = {from: parseFloat(v.0), to: parseFloat(v.1)}
v = (@input.value or '').split(/\s*~\s*/)
v = {from: parseFloat((v.0 or '').trim!), to: parseFloat((v.1 or '').trim!)}
if isNaN(v.from) => v.from = 0
if isNaN(v.to) => v.from = 0
@repos v.from, true, false, true, false
@repos v.to, true, false, true, true
else @repos @input.value, true, false, true
else
v = parseFloat((@input.value or '').trim!)
if isNaN(v) => v = 0
@repos v, true, false, true
@input.addEventListener \change, handle
@input.addEventListener \input, handle

Expand Down Expand Up @@ -86,7 +91,7 @@ ldSlider.prototype = Object.create(Object.prototype) <<< do
clearTimeout @debounce
@debounce = setTimeout (~>
if @range =>
v = "#{@val.from} to #{@val.to}"
v = "#{@val.from} ~ #{@val.to}"
if @input.value != v => @input.value = v
else
if @input.value != @val.from => @input.value = @val.from
Expand Down
20 changes: 15 additions & 5 deletions web/static/assets/lib/ldrs/dev/ldrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@ ldSlider = function(opt){
handle = function(){
var v;
if (this$.range) {
v = (this$.input.value || '').split(/\s+to\s+/);
v = (this$.input.value || '').split(/\s*~\s*/);
v = {
from: parseFloat(v[0]),
to: parseFloat(v[1])
from: parseFloat((v[0] || '').trim()),
to: parseFloat((v[1] || '').trim())
};
if (isNaN(v.from)) {
v.from = 0;
}
if (isNaN(v.to)) {
v.from = 0;
}
this$.repos(v.from, true, false, true, false);
return this$.repos(v.to, true, false, true, true);
} else {
return this$.repos(this$.input.value, true, false, true);
v = parseFloat((this$.input.value || '').trim());
if (isNaN(v)) {
v = 0;
}
return this$.repos(v, true, false, true);
}
};
this.input.addEventListener('change', handle);
Expand Down Expand Up @@ -127,7 +137,7 @@ ldSlider.prototype = import$(Object.create(Object.prototype), {
return this.debounce = setTimeout(function(){
var v;
if (this$.range) {
v = this$.val.from + " to " + this$.val.to;
v = this$.val.from + " ~ " + this$.val.to;
if (this$.input.value !== v) {
return this$.input.value = v;
}
Expand Down
Loading

0 comments on commit 783b268

Please sign in to comment.