Skip to content

Commit 81636e1

Browse files
committed
- support unit option
- bump version
1 parent 815a64d commit 81636e1

File tree

9 files changed

+33
-27
lines changed

9 files changed

+33
-27
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## v3.1.0
4+
5+
- support `unit` option
6+
7+
38
## v3.0.6
49

510
- tweak ui layout by increasing height with 2px

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ You can use an optional `data-class` attribute in `input` to define the classes
7070
- `label.min` - text for showing in minimal value label
7171
- `label.max` - text for showing in maximal value label
7272
- `label.ptr(v)` - function that convert v ( value ) to the returned customized string that representing v.
73+
* `unit`: unit for showing in label
7374

7475

7576
## Decorating Classes

dist/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
ref$ = !mouse.alt
9898
? [this$.el.h.p, this$.val.from]
9999
: [this$.el.h.q, this$.val.to], p = ref$[0], v = ref$[1];
100-
return p.innerText = this$.label.ptr(Math.round(10000 * v) / 10000);
100+
return p.innerText = this$.label.ptr(Math.round(10000 * v) / 10000) + (this$.opt.unit || '');
101101
},
102102
prepare: function(e){
103103
mouse.alt = e.target && e.target.classList && e.target.classList.contains('alt') ? true : false;
@@ -198,14 +198,14 @@
198198
}
199199
}
200200
}, this.opt.label || {});
201-
this.el.h.l.innerText = this.label.min != null
201+
this.el.h.l.innerText = (this.label.min != null
202202
? this.label.min
203-
: this.opt.min;
204-
this.el.h.r.innerText = this.label.max != null
203+
: this.opt.min) + (this.opt.unit || '');
204+
this.el.h.r.innerText = (this.label.max != null
205205
? this.label.max
206-
: this.opt.max;
207-
this.el.h.p.innerText = this.label.ptr(this.opt.from);
208-
this.el.h.q.innerText = this.label.ptr(this.opt.to);
206+
: this.opt.max) + (this.opt.unit || '');
207+
this.el.h.p.innerText = this.label.ptr(this.opt.from) + (this.opt.unit || '');
208+
this.el.h.q.innerText = this.label.ptr(this.opt.to) + (this.opt.unit || '');
209209
this.root.classList[this.opt.limitMax != null ? 'add' : 'remove']('limit');
210210
this.range = this.opt.range != null
211211
? this.opt.range
@@ -317,7 +317,7 @@
317317
: Math.max(xs.from, xs.to) - left + 0.5;
318318
/* update value and position into view */
319319
hbox = elH.getBoundingClientRect();
320-
elH.innerText = this.label.ptr(Math.round(10000 * v) / 10000);
320+
elH.innerText = this.label.ptr(Math.round(10000 * v) / 10000) + (this.opt.unit || '');
321321
elH.style.left = 100 * (0.01 * x * rbox.width) / rbox.width + "%";
322322
elH.style.transform = "translate(-50%,0)";
323323
elL.style.left = x + "%";

dist/index.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "ldslider",
44
"license": "MIT",
55
"description": "Slider Library in Vanilla JS",
6-
"version": "3.0.6",
6+
"version": "3.1.0",
77
"style": "dist/index.min.css",
88
"browser": "dist/index.min.js",
99
"main": "dist/index.min.js",

src/index.ls

+6-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ ldslider = (opt={}) ->
7070
document.removeEventListener \mouseup, mouse.up
7171
document.removeEventListener \mousemove, mouse.move
7272
[p,v] = if !mouse.alt => [@el.h.p, @val.from] else [@el.h.q, @val.to]
73-
p.innerText = @label.ptr(Math.round(10000 * v) / 10000)
73+
p.innerText = @label.ptr(Math.round(10000 * v) / 10000) + (@opt.unit or '')
7474
prepare: (e) ~>
7575
mouse.alt = if e.target and e.target.classList and e.target.classList.contains \alt => true
7676
else false
@@ -120,10 +120,10 @@ ldslider.prototype = Object.create(Object.prototype) <<< do
120120
else if it == @opt.max and @label.max? => @label.max
121121
else it
122122
} <<< (@opt.label or {})
123-
@el.h.l.innerText = if @label.min? => @label.min else @opt.min
124-
@el.h.r.innerText = if @label.max? => @label.max else @opt.max
125-
@el.h.p.innerText = @label.ptr(@opt.from)
126-
@el.h.q.innerText = @label.ptr(@opt.to)
123+
@el.h.l.innerText = (if @label.min? => @label.min else @opt.min) + (@opt.unit or '')
124+
@el.h.r.innerText = (if @label.max? => @label.max else @opt.max) + (@opt.unit or '')
125+
@el.h.p.innerText = @label.ptr(@opt.from) + (@opt.unit or '')
126+
@el.h.q.innerText = @label.ptr(@opt.to) + (@opt.unit or '')
127127
@root.classList[if @opt.limit-max? => \add else \remove] \limit
128128
@range = if (@opt.range?) => @opt.range else if @root.classList.contains(\range) => true else false
129129
if @range => @root.classList.toggle \range, @range
@@ -185,7 +185,7 @@ ldslider.prototype = Object.create(Object.prototype) <<< do
185185

186186
/* update value and position into view */
187187
hbox = el-h.getBoundingClientRect!
188-
el-h.innerText = @label.ptr(Math.round(10000 * v) / 10000)
188+
el-h.innerText = @label.ptr(Math.round(10000 * v) / 10000) + (@opt.unit or '')
189189
el-h.style.left = "#{100 * (0.01 * x * rbox.width) / rbox.width}%"
190190
el-h.style.transform = "translate(-50%,0)"
191191
el-l.style.left = "#x%"

0 commit comments

Comments
 (0)