Skip to content

Commit 6532158

Browse files
committed
Fix slider constraints on init conditions #1009
1 parent 7be853b commit 6532158

File tree

10 files changed

+53
-13
lines changed

10 files changed

+53
-13
lines changed

CHANGELOG.MD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
### 14.0.3 (*2019-10-10*)
4+
- Fixed: Initialising handle values near the slider edge does not always respect `margin` (#1009);
5+
36
### 14.0.2 (*2019-06-28*)
47
- Fixed: Keyboard interaction uses formatter when it does not need to (#1000);
58

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ For help with implementing this slider, ask your question on [stackoverflow](htt
55

66
While I'm happy to help if you can't figure something out, please note this: I won't debug screenshots or issues that do not include **an example with code** that reproduces it. I also won't dig through your production site or huge chunks of unrelated code. I also won't implement your business requirements for you.
77

8+
# Tooling
9+
10+
Please run the following tooling before submitting a pull request:
11+
12+
```bash
13+
npm run lint
14+
npm run format
15+
```
16+
817
# Pull requests
918
- Detail (in the pull request comment) what your changes do.
1019
- When applicable, include new unit tests.

distribute/nouislider.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! nouislider - 14.0.2 - 6/28/2019 */
1+
/*! nouislider - 14.0.3 - 10/10/2019 */
22
/* Functional styling;
33
* These styles are required for noUiSlider to function.
44
* You don't need to change these rules to apply your design.

distribute/nouislider.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! nouislider - 14.0.2 - 6/28/2019 */
1+
/*! nouislider - 14.0.3 - 10/10/2019 */
22
(function(factory) {
33
if (typeof define === "function" && define.amd) {
44
// AMD. Register as an anonymous module.
@@ -13,7 +13,7 @@
1313
})(function() {
1414
"use strict";
1515

16-
var VERSION = "14.0.2";
16+
var VERSION = "14.0.3";
1717

1818
//region Helper Methods
1919

@@ -2198,10 +2198,15 @@
21982198
setHandle(handleNumber, resolveToValue(values[handleNumber], handleNumber), true, false);
21992199
});
22002200

2201-
// Second pass. Now that all base values are set, apply constraints
2202-
scope_HandleNumbers.forEach(function(handleNumber) {
2203-
setHandle(handleNumber, scope_Locations[handleNumber], true, true);
2204-
});
2201+
var i = scope_HandleNumbers.length === 1 ? 0 : 1;
2202+
2203+
// Secondary passes. Now that all base values are set, apply constraints.
2204+
// Iterate all handles to ensure constraints are applied for the entire slider (Issue #1009)
2205+
for (; i < scope_HandleNumbers.length; ++i) {
2206+
scope_HandleNumbers.forEach(function(handleNumber) {
2207+
setHandle(handleNumber, scope_Locations[handleNumber], true, true);
2208+
});
2209+
}
22052210

22062211
setZindex();
22072212

distribute/nouislider.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

distribute/nouislider.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nouislider",
3-
"version": "14.0.2",
3+
"version": "14.0.3",
44
"main": "distribute/nouislider.js",
55
"style": "distribute/nouislider.min.css",
66
"license": "MIT",

src/nouislider.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,9 +2198,10 @@
21982198
});
21992199

22002200
var i = scope_HandleNumbers.length === 1 ? 0 : 1;
2201+
2202+
// Secondary passes. Now that all base values are set, apply constraints.
2203+
// Iterate all handles to ensure constraints are applied for the entire slider (Issue #1009)
22012204
for (; i < scope_HandleNumbers.length; ++i) {
2202-
// Issue #1009
2203-
// Second pass. Now that all base values are set, apply constraints
22042205
scope_HandleNumbers.forEach(function(handleNumber) {
22052206
setHandle(handleNumber, scope_Locations[handleNumber], true, true);
22062207
});

tests/slider.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<script src="slider_setting-getting.js"></script>
5959
<script src="slider_update.js"></script>
6060
<script src="slider_get-step.js"></script>
61+
<script src="slider_init_max.js"></script>
6162
<script src="slider_unordered.js"></script>
6263
<script src="slider_errors.js"></script>
6364
<script src="slider_binding.js"></script>

tests/slider_init_max.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
QUnit.test("Test init of slider values near max", function (assert) {
2+
3+
document.getElementById('qunit-fixture').innerHTML = '<div class="slider"></div>';
4+
5+
var slider = document.getElementById('qunit-fixture').querySelector('.slider');
6+
var max = 10;
7+
8+
noUiSlider.create(slider, {
9+
start: [max, max, max, max],
10+
step: 1,
11+
margin: 1,
12+
tooltips: true,
13+
pips: {mode: 'count', values: 5},
14+
range: {
15+
'min': 0,
16+
'max': max
17+
}
18+
});
19+
20+
assert.deepEqual(slider.noUiSlider.get(), ['7.00', '8.00', '9.00', '10.00']);
21+
});

0 commit comments

Comments
 (0)