]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Use pull request #11409 from veselinn/fix/slider-handle-negative-data-start for v6.5.0
authorVeselin Nikolov <vesoNikolov@gmail.com>
Sat, 25 Aug 2018 20:33:39 +0000 (22:33 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Sat, 25 Aug 2018 20:33:39 +0000 (22:33 +0200)
81fc284e9 fix: slider handle negative data-start values
da0b014de fix: remove unnecessary if from slider
9851a17ff test: add tests for Slider._adjustValue

Signed-off-by: Nicolas Coden <nicolas@ncoden.fr>
js/foundation.slider.js
test/javascript/components/slider.js

index e7d4e18705f1fc575e34e32c8d8332d9eb8785f0..6f29fbe21025ede2885d5e3761f3c91c170d20ba 100644 (file)
@@ -426,7 +426,11 @@ class Slider extends Plugin {
     else {
       val = value;
     }
-    left = val % step;
+    if (val >= 0) {
+      left = val % step;
+    } else {
+      left = step + (val % step);
+    }
     prev_val = val - left;
     next_val = prev_val + step;
     if (left === 0) {
index 364919af2f3e29fd7ea6aec6ba3ea619d362494a..9c1480aca750ce540cb602dc3a529f69bf051be5 100644 (file)
@@ -153,6 +153,30 @@ describe('Slider', function() {
     });
   });
 
+  describe('adjustValue()', function() {
+    it('handles positive values', function() {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.Slider($html, {});
+
+      plugin._adjustValue(null, 1).should.equal(1);
+      plugin._adjustValue(null, 2).should.equal(2);
+      plugin._adjustValue(null, 1.2).should.equal(1);
+      plugin._adjustValue(null, 1.9).should.equal(2);
+      plugin._adjustValue(null, 1.5).should.equal(2);
+    });
+
+    it('handles negative values', function() {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.Slider($html, {});
+
+      plugin._adjustValue(null, -1).should.equal(-1);
+      plugin._adjustValue(null, -2).should.equal(-2);
+      plugin._adjustValue(null, -1.2).should.equal(-1);
+      plugin._adjustValue(null, -1.9).should.equal(-2);
+      plugin._adjustValue(null, -1.5).should.equal(-1);
+    });
+  });
+
   describe('keyboard events', function() {
     it('sets value to minimum using HOME', function() {
       $html = $(template).appendTo('body');