]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
slider stepping 7910/head
authorTvrtko <tvrtkom@gmail.com>
Mon, 18 Jan 2016 19:58:53 +0000 (20:58 +0100)
committerTvrtko <tvrtkom@gmail.com>
Mon, 18 Jan 2016 19:58:53 +0000 (20:58 +0100)
js/foundation.slider.js

index 773eb9a4929ac8054f39a0f8485388b0c9664a94..faf4e8addd02d199f73bc5365d1832a48aedeb73 100644 (file)
     this.inputs.eq(idx).attr({
       'id': id,
       'max': this.options.end,
-      'min': this.options.start
-
+      'min': this.options.start,
+      'step': this.options.step
     });
     this.handles.eq(idx).attr({
       'role': 'slider',
           // eleDim = this.$element[0].getBoundingClientRect()[param],
           offsetPct = percent(barXY, barDim);
       value = (this.options.end - this.options.start) * offsetPct;
+      value = _this._adjustValue(null, value);
       hasVal = false;
 
       if(!$handle){//figure out which handle it is, pass it to the next function.
       }
 
     }else{//change event on input
-      value = val;
+      value = this._adjustValue($handle);
       hasVal = true;
     }
 
     this._setHandlePos($handle, value, hasVal);
   };
+
+  /**
+   * Adjustes value for handle in regard to step value. returns adjusted value
+   * @function
+   * @private
+   * @param {jQuery} $handle - the selected handle.
+   * @param {Number} value - value to adjust. used if $handle is falsy
+   */
+  Slider.prototype._adjustValue = function($handle, value) {
+    var val,
+      step = this.options.step,
+      div = parseFloat(step/2),
+      left, prev_val, next_val;
+    if(!!$handle) {
+      val = parseFloat($handle.attr('aria-valuenow'));
+    }
+    else {
+      val = value;
+    }
+    left = val % step;
+    prev_val = val - left;
+    next_val = prev_val + step;
+    if (left === 0) {
+      return val;
+    }
+    val = val >= prev_val + div ? next_val : prev_val;
+    return val;
+  };
+
   /**
    * Adds event listeners to the slider elements.
    * @function
       this.$element.off('click.zf.slider').on('click.zf.slider', function(e){
         if(_this.$element.data('dragging')){ return false; }
         _this.animComplete = false;
-        if(_this.options.doubleSided){
-          _this._handleEvent(e);
-        }else{
-          _this._handleEvent(e, _this.$handle);
+
+        if(!$(e.target).is('[data-slider-handle]')) {
+          if (_this.options.doubleSided) {
+            _this._handleEvent(e);
+          } else {
+            _this._handleEvent(e, _this.$handle);
+          }
         }
       });
     }