Skip to content

Commit 2b6f091

Browse files
author
matthewcsimpson
committed
pr feedback: version
1 parent 7b96473 commit 2b6f091

4 files changed

Lines changed: 68 additions & 10 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,17 @@ Multiple Scripts: Add as many scripts as you need to your project by referencing
8282
**Range sliders:** each script is **self-contained** (one tag). Use **`RangeSlider.js`** for custom thumbs or **`RangeSliderSimple.js`** for native thumbs only. Use jsDelivr (not raw `githubusercontent.com`, which often serves `text/plain` and blocks execution).
8383

8484
```
85-
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@main/Dist/Functional/RangeSlider.js"></script>
85+
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@1/Dist/Functional/RangeSlider.js"></script>
8686
```
8787

88-
Native-thumb variant:
88+
Native-thumb variant (`RangeSliderSimple` is **1.0.0** in source; pin further with a [release tag](https://github.com/TheCodeRaccoons/WebTricks/releases) or commit hash if you need an exact file):
8989

9090
```
91-
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@main/Dist/Functional/RangeSliderSimple.js"></script>
91+
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@1/Dist/Functional/RangeSliderSimple.js"></script>
9292
```
9393

94+
Prefer **`@1`**, a **semver release tag** (e.g. `@v1.0.0`), or a **commit SHA** over **`@main`** for production embeds so the script URL does not move unexpectedly.
95+
9496
If a page uses **both** slider types, you may include **both** scripts; they use separate attribute namespaces (`wt-rangeslider-*` vs `wt-rangeslidersimple-*`).
9597

9698
Ready to Use: Once imported, the scripts initialize automatically, provided the correct HTML attributes are in place.

__tests__/RangeSliderSimple.test.js

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,19 @@ describe('RangeSliderSimple', () => {
4444
const right = wrapper.querySelector(
4545
'[wt-rangeslidersimple-element="input-right"]',
4646
);
47+
const displayFrom = wrapper.querySelector(
48+
'[wt-rangeslidersimple-display="from"]',
49+
);
50+
const displayTo = wrapper.querySelector(
51+
'[wt-rangeslidersimple-display="to"]',
52+
);
4753
expect(left.value).toBe('0');
4854
expect(right.value).toBe('100');
55+
expect(left.min).toBe('0');
56+
expect(left.max).toBe('100');
57+
expect(left.step).toBe('1');
58+
expect(displayFrom.textContent).toBe('0');
59+
expect(displayTo.textContent).toBe('100');
4960
expect(instance.sliderMin).toBe(0);
5061
expect(instance.sliderMax).toBe(100);
5162
});
@@ -94,18 +105,57 @@ describe('RangeSliderSimple', () => {
94105
'[wt-rangeslidersimple-element="slider-wrapper"]',
95106
);
96107
const instance = new RangeSliderSimple(wrapper);
108+
109+
instance.setTo('5');
110+
instance.setFrom('4.9');
111+
112+
// min(4.9, 5 - 0.3) = 4.7 — parseInt would wrongly yield 4
113+
expect(
114+
wrapper.querySelector('[wt-rangeslidersimple-element="input-left"]')
115+
.value,
116+
).toBe('4.7');
117+
expect(
118+
wrapper.querySelector('[wt-rangeslidersimple-element="input-right"]')
119+
.value,
120+
).toBe('5');
121+
});
122+
123+
test('constrainRightValue keeps at least minDifference above left handle', () => {
124+
mountSlider();
125+
const wrapper = document.querySelector(
126+
'[wt-rangeslidersimple-element="slider-wrapper"]',
127+
);
128+
const instance = new RangeSliderSimple(wrapper);
97129
const left = wrapper.querySelector(
98130
'[wt-rangeslidersimple-element="input-left"]',
99131
);
100132
const right = wrapper.querySelector(
101133
'[wt-rangeslidersimple-element="input-right"]',
102134
);
103135

104-
instance.setTo('5');
105-
instance.setFrom('4.9');
136+
instance.setFrom('60');
137+
instance.setTo('30');
106138

107-
// min(4.9, 5 - 0.3) = 4.7 — parseInt would wrongly yield 4
108-
expect(left.value).toBe('4.7');
109-
expect(right.value).toBe('5');
139+
// max(30, 60 + 1) = 61 with mindifference === 1
140+
expect(left.value).toBe('60');
141+
expect(right.value).toBe('61');
142+
});
143+
144+
test('reset restores min and max on both inputs', () => {
145+
mountSlider();
146+
const wrapper = document.querySelector(
147+
'[wt-rangeslidersimple-element="slider-wrapper"]',
148+
);
149+
const instance = new RangeSliderSimple(wrapper);
150+
instance.setRange('40', '50');
151+
instance.reset();
152+
const left = wrapper.querySelector(
153+
'[wt-rangeslidersimple-element="input-left"]',
154+
);
155+
const right = wrapper.querySelector(
156+
'[wt-rangeslidersimple-element="input-right"]',
157+
);
158+
expect(left.value).toBe('0');
159+
expect(right.value).toBe('100');
110160
});
111161
});

docs/Functional/RangeSlider.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ Add the script to your project and include the required attributes and elements
3030

3131
Self-contained: **one** script tag. Use [jsDelivr](https://www.jsdelivr.com/) (not raw GitHub URLs) so the MIME type is JavaScript.
3232

33+
Pin to a **Git tag** (not `@main`) so embeds don’t change when the default branch moves. This module is **1.1.0** above—use that release ref when it exists:
34+
3335
```html
34-
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@main/Dist/Functional/RangeSlider.js"></script>
36+
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@v1.1.0/Dist/Functional/RangeSlider.js"></script>
3537
```
3638

39+
If `v1.1.0` is not published on the repo yet, use another tag from [Releases](https://github.com/TheCodeRaccoons/WebTricks/releases), a **commit SHA**, or `@1` (major ref; same idea as the main README) until you ship a matching tag.
40+
3741
### Required Attributes
3842

3943
- `wt-rangeslider-element="slider-wrapper"` - Container element

docs/Functional/RangeSliderSimple.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ The script is **self-contained** (single file, one `<script>` tag).
2626
One script tag. Use [jsDelivr](https://www.jsdelivr.com/) (not raw GitHub URLs) so the MIME type is JavaScript.
2727

2828
```html
29-
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@main/Dist/Functional/RangeSliderSimple.js"></script>
29+
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@1/Dist/Functional/RangeSliderSimple.js"></script>
3030
```
3131

32+
Pin with a [GitHub release](https://github.com/TheCodeRaccoons/WebTricks/releases) tag or commit hash instead of `@main` when you need a fixed build.
33+
3234
## Required attributes
3335

3436
- `wt-rangeslidersimple-element="slider-wrapper"` — outer container

0 commit comments

Comments
 (0)