Skip to content

Commit 2313a4e

Browse files
author
matthewcsimpson
committed
feat: rangeslidersimple
1 parent abb6446 commit 2313a4e

23 files changed

Lines changed: 1310 additions & 525 deletions

Dist/Functional/RangeSlider.js

Lines changed: 399 additions & 504 deletions
Large diffs are not rendered by default.

Dist/Functional/RangeSliderSimple.js

Lines changed: 485 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ Multiple Scripts: Add as many scripts as you need to your project by referencing
7878
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/webtricks@1/dist/Functional/CMSFilter.min.js"></script>
7979
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/webtricks@1/dist/Functional/FormCheck.min.js"></script>
8080
```
81+
82+
**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).
83+
84+
```
85+
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@main/Dist/Functional/RangeSlider.js"></script>
86+
```
87+
88+
Native-thumb variant:
89+
90+
```
91+
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@main/Dist/Functional/RangeSliderSimple.js"></script>
92+
```
93+
94+
If a page uses **both** slider types, you may include **both** scripts; they use separate attribute namespaces (`wt-rangeslider-*` vs `wt-rangeslidersimple-*`).
95+
8196
Ready to Use: Once imported, the scripts initialize automatically, provided the correct HTML attributes are in place.
8297

8398

__tests__/RangeSlider.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/** @jest-environment jsdom */
2+
3+
Object.defineProperty(document, 'readyState', { value: 'loading', configurable: true });
4+
5+
describe('RangeSlider', () => {
6+
let RangeSlider;
7+
let InitializeRangeSlider;
8+
9+
beforeEach(() => {
10+
document.body.innerHTML = '';
11+
window.webtricks = [];
12+
jest.resetModules();
13+
({ RangeSlider, InitializeRangeSlider } = require('../Dist/Functional/RangeSlider.js'));
14+
});
15+
16+
function mountRangeSlider() {
17+
document.body.innerHTML = `
18+
<div wt-rangeslider-element="slider-wrapper">
19+
<div wt-rangeslider-element="slider"
20+
wt-rangeslider-min="0"
21+
wt-rangeslider-max="100"
22+
wt-rangeslider-steps="1">
23+
<div wt-rangeslider-element="range"></div>
24+
<div wt-rangeslider-element="thumb-left"></div>
25+
<div wt-rangeslider-element="thumb-right"></div>
26+
<input type="range" wt-rangeslider-element="input-left" />
27+
<input type="range" wt-rangeslider-element="input-right" />
28+
</div>
29+
</div>
30+
`;
31+
}
32+
33+
test('constructor sets initial values from min/max', () => {
34+
mountRangeSlider();
35+
const wrapper = document.querySelector(
36+
'[wt-rangeslider-element="slider-wrapper"]',
37+
);
38+
new RangeSlider(wrapper);
39+
const left = wrapper.querySelector('[wt-rangeslider-element="input-left"]');
40+
const right = wrapper.querySelector('[wt-rangeslider-element="input-right"]');
41+
expect(left.value).toBe('0');
42+
expect(right.value).toBe('100');
43+
});
44+
45+
test('InitializeRangeSlider pushes instance to webtricks', () => {
46+
mountRangeSlider();
47+
InitializeRangeSlider();
48+
expect(window.webtricks.some((e) => e.RangeSlider)).toBe(true);
49+
});
50+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/** @jest-environment jsdom */
2+
3+
Object.defineProperty(document, 'readyState', { value: 'loading', configurable: true });
4+
5+
describe('RangeSliderSimple', () => {
6+
let RangeSliderSimple;
7+
let InitializeRangeSliderSimple;
8+
9+
beforeEach(() => {
10+
document.body.innerHTML = '';
11+
window.webtricks = [];
12+
jest.resetModules();
13+
({
14+
RangeSliderSimple,
15+
InitializeRangeSliderSimple,
16+
} = require('../Dist/Functional/RangeSliderSimple.js'));
17+
});
18+
19+
function mountSlider() {
20+
document.body.innerHTML = `
21+
<div wt-rangeslidersimple-element="slider-wrapper">
22+
<div wt-rangeslidersimple-display="from">0</div>
23+
<div wt-rangeslidersimple-display="to">100</div>
24+
<div wt-rangeslidersimple-element="slider"
25+
wt-rangeslidersimple-min="0"
26+
wt-rangeslidersimple-max="100"
27+
wt-rangeslidersimple-steps="1">
28+
<input type="range" wt-rangeslidersimple-element="input-left" />
29+
<input type="range" wt-rangeslidersimple-element="input-right" />
30+
</div>
31+
</div>
32+
`;
33+
}
34+
35+
test('constructor wires inputs and displays', () => {
36+
mountSlider();
37+
const wrapper = document.querySelector(
38+
'[wt-rangeslidersimple-element="slider-wrapper"]',
39+
);
40+
const instance = new RangeSliderSimple(wrapper);
41+
const left = wrapper.querySelector(
42+
'[wt-rangeslidersimple-element="input-left"]',
43+
);
44+
const right = wrapper.querySelector(
45+
'[wt-rangeslidersimple-element="input-right"]',
46+
);
47+
expect(left.value).toBe('0');
48+
expect(right.value).toBe('100');
49+
expect(instance.sliderMin).toBe(0);
50+
expect(instance.sliderMax).toBe(100);
51+
});
52+
53+
test('InitializeRangeSliderSimple pushes instance to webtricks', () => {
54+
mountSlider();
55+
InitializeRangeSliderSimple();
56+
expect(window.webtricks.some((e) => e.RangeSliderSimple)).toBe(true);
57+
});
58+
});

docs/Functional/CookieConsent.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# CookieConsent
22

33
## Version
4+
45
Current Version: 1.0.0
56

67
## Description
8+
79
CookieConsent is a GDPR-compliant cookie consent management system that provides granular control over cookie preferences and script loading. It supports multiple consent categories, manages consent persistence, and controls script loading based on user preferences.
810

911
## Functionality
12+
1013
- Cookie consent banner management
1114
- Multiple consent categories
1215
- Granular script loading control
@@ -17,25 +20,30 @@ CookieConsent is a GDPR-compliant cookie consent management system that provides
1720
- Category-based script loading
1821

1922
## Usage
23+
2024
Add the script to your project and include the required attributes on your banner and script elements.
2125

2226
### Installation
27+
2328
```html
2429
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@1/Dist/Functional/CookieConsent.min.js"></script>
2530
```
2631

2732
### Required Attributes
33+
2834
- `wt-cookieconsent-element="banner"` - Applied to the main cookie banner container
2935
- `wt-cookieconsent-script="category"` - Applied to scripts that require consent
3036

3137
### Optional Elements and Attributes
38+
3239
- `wt-cookieconsent-element="accept-all"` - Accept all cookies button
3340
- `wt-cookieconsent-element="accept-necessary"` - Accept necessary cookies only button
3441
- `wt-cookieconsent-element="manage-cookies"` - Manage cookies settings button
3542
- `wt-cookieconsent-element="categories-form"` - Form for custom category selection
3643
- `wt-cookieconsent-category="category-name"` - Category checkbox inputs
3744

3845
## Considerations
46+
3947
1. **GDPR Compliance**: Supports granular consent management
4048
2. **Script Loading**: Automatically handles script loading based on consent
4149
3. **Persistence**: Stores consent in cookies with configurable expiry
@@ -45,6 +53,7 @@ Add the script to your project and include the required attributes on your banne
4553
## Examples
4654

4755
### Basic Implementation
56+
4857
```html
4958
<!-- Cookie Banner -->
5059
<div wt-cookieconsent-element="banner">
@@ -59,6 +68,7 @@ Add the script to your project and include the required attributes on your banne
5968
```
6069

6170
### Advanced Implementation with Categories
71+
6272
```html
6373
<div wt-cookieconsent-element="banner">
6474
<p>Choose your cookie preferences</p>
@@ -102,6 +112,7 @@ Add the script to your project and include the required attributes on your banne
102112
```
103113

104114
### Inline Script Implementation
115+
105116
```html
106117
<!-- Inline script with consent -->
107118
<script wt-cookieconsent-script="analytics">
@@ -111,8 +122,9 @@ Add the script to your project and include the required attributes on your banne
111122
```
112123

113124
### Common Use Cases
125+
114126
1. GDPR compliance implementation
115127
2. Analytics script management
116128
3. Marketing pixel control
117129
4. A/B testing script management
118-
5. Third-party service integration
130+
5. Third-party service integration

docs/Functional/CopyToClipboard.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# CopyToClipboard
22

33
## Version
4+
45
Current Version: 1.0.0
56

67
## Description
8+
79
CopyToClipboard is a utility script that enables copying text to clipboard with visual feedback. It supports custom success messages, styling, and timeout durations for the feedback display.
810

911
## Functionality
12+
1013
- One-click text copying
1114
- Customizable success messages
1215
- Visual feedback through classes
@@ -16,25 +19,30 @@ CopyToClipboard is a utility script that enables copying text to clipboard with
1619
- Multiple instances support
1720

1821
## Usage
22+
1923
Add the script to your project and include the required attributes on your copy elements.
2024

2125
### Installation
26+
2227
```html
2328
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@1/Dist/Functional/CopyToClipboard.min.js"></script>
2429
```
2530

2631
### Required Attributes
32+
2733
- `wt-copycb-element="container"` - Applied to the container element
2834
- `wt-copycb-element="trigger"` - Applied to the click trigger element
2935
- `wt-copycb-element="target"` - Applied to the element containing text to copy
3036

3137
### Optional Attributes
38+
3239
- `wt-copycb-message="Copied!"` - Custom success message
3340
- `wt-copycb-active="is-copy"` - CSS class for active state
3441
- `wt-copycb-timeout="2000"` - Duration to show success state (ms)
3542
- `wt-copycb-element="texttarget"` - Element within trigger to update with success message
3643

3744
## Considerations
45+
3846
1. **Clipboard API**: Uses modern navigator.clipboard API
3947
2. **State Management**: Automatically resets to original state
4048
3. **Visual Feedback**: Supports both text and class-based feedback
@@ -44,6 +52,7 @@ Add the script to your project and include the required attributes on your copy
4452
## Examples
4553

4654
### Basic Implementation
55+
4756
```html
4857
<div wt-copycb-element="container">
4958
<button wt-copycb-element="trigger">Copy Text</button>
@@ -52,6 +61,7 @@ Add the script to your project and include the required attributes on your copy
5261
```
5362

5463
### Advanced Implementation
64+
5565
```html
5666
<div wt-copycb-element="container">
5767
<button wt-copycb-element="trigger"
@@ -68,6 +78,7 @@ Add the script to your project and include the required attributes on your copy
6878
```
6979

7080
### CSS Styling Example
81+
7182
```css
7283
/* Default state */
7384
[wt-copycb-element="trigger"] {
@@ -82,15 +93,17 @@ Add the script to your project and include the required attributes on your copy
8293
```
8394

8495
### Common Use Cases
96+
8597
1. Code snippet copying
8698
2. Share link buttons
8799
3. Reference number copying
88100
4. Contact information copying
89101
5. Form field duplication
90102

91103
### Best Practices
104+
92105
1. Always provide visual feedback for copy action
93106
2. Use clear and concise success messages
94107
3. Consider mobile touch interactions
95108
4. Maintain original styling during state changes
96-
5. Include fallback for unsupported browsers
109+
5. Include fallback for unsupported browsers

docs/Functional/CountUp.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# CountUp
22

33
## Version
4+
45
Current Version: 1.0.0
56

67
## Description
8+
79
CountUp is a lightweight animation script that creates counting animations from zero to a target number. It supports customizable counting speed, step size, and allows adding prefix and suffix text to the displayed number.
810

911
## Functionality
12+
1013
- Animated number counting
1114
- Configurable target number
1215
- Adjustable animation speed
@@ -16,24 +19,29 @@ CountUp is a lightweight animation script that creates counting animations from
1619
- Error handling
1720

1821
## Usage
22+
1923
Add the script to your project and include the required attributes on your counter elements.
2024

2125
### Installation
26+
2227
```html
2328
<script src="https://cdn.jsdelivr.net/gh/TheCodeRaccoons/WebTricks@1/Dist/Functional/CountUp.min.js"></script>
2429
```
2530

2631
### Required Attributes
32+
2733
- `wt-countup-element="counter"` - Applied to the element that will display the counting animation
2834
- `wt-countup-target="100"` - The target number to count up to
2935

3036
### Optional Attributes
37+
3138
- `wt-countup-prefix="$"` - Text to display before the number
3239
- `wt-countup-suffix="+"` - Text to display after the number
3340
- `wt-countup-step="5"` - Number to increment by (default: 1)
3441
- `wt-countup-speed="10"` - Animation speed in milliseconds (default: 10)
3542

3643
## Considerations
44+
3745
1. **Performance**: Uses setInterval for animation timing
3846
2. **Memory Management**: Automatically clears interval when target is reached
3947
3. **Error Handling**: Gracefully handles initialization errors
@@ -43,6 +51,7 @@ Add the script to your project and include the required attributes on your count
4351
## Examples
4452

4553
### Basic Implementation
54+
4655
```html
4756
<div wt-countup-element="counter"
4857
wt-countup-target="100">
@@ -51,6 +60,7 @@ Add the script to your project and include the required attributes on your count
5160
```
5261

5362
### Advanced Implementation
63+
5464
```html
5565
<div wt-countup-element="counter"
5666
wt-countup-target="1000"
@@ -63,6 +73,7 @@ Add the script to your project and include the required attributes on your count
6373
```
6474

6575
### Multiple Counters
76+
6677
```html
6778
<!-- Basic counter -->
6879
<div wt-countup-element="counter"
@@ -88,8 +99,9 @@ Add the script to your project and include the required attributes on your count
8899
```
89100

90101
### Common Use Cases
102+
91103
1. Statistics displays
92104
2. Progress indicators
93105
3. Achievement counters
94106
4. Price animations
95-
5. Loading indicators
107+
5. Loading indicators

0 commit comments

Comments
 (0)