"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(e,i,s){return i&&t(e.prototype,i),s&&t(e,s),e}}();!function(t){function e(t,e){return t/e}function i(t,e,i,s){return Math.abs(t.position()[e]+t[s]()/2-i)}function s(t,e){return Math.log(e)/Math.log(t)}var n=function(){function n(e,i){_classCallCheck(this,n),this.$element=e,this.options=t.extend({},n.defaults,this.$element.data(),i),this._init(),Foundation.registerPlugin(this,"Slider"),Foundation.Keyboard.register("Slider",{ltr:{ARROW_RIGHT:"increase",ARROW_UP:"increase",ARROW_DOWN:"decrease",ARROW_LEFT:"decrease",SHIFT_ARROW_RIGHT:"increase_fast",SHIFT_ARROW_UP:"increase_fast",SHIFT_ARROW_DOWN:"decrease_fast",SHIFT_ARROW_LEFT:"decrease_fast"},rtl:{ARROW_LEFT:"increase",ARROW_RIGHT:"decrease",SHIFT_ARROW_LEFT:"increase_fast",SHIFT_ARROW_RIGHT:"decrease_fast"}})}return _createClass(n,[{key:"_init",value:function(){this.inputs=this.$element.find("input"),this.handles=this.$element.find("[data-slider-handle]"),this.$handle=this.handles.eq(0),this.$input=this.inputs.length?this.inputs.eq(0):t("#"+this.$handle.attr("aria-controls")),this.$fill=this.$element.find("[data-slider-fill]").css(this.options.vertical?"height":"width",0);var e=!1;(this.options.disabled||this.$element.hasClass(this.options.disabledClass))&&(this.options.disabled=!0,this.$element.addClass(this.options.disabledClass)),this.inputs.length||(this.inputs=t().add(this.$input),this.options.binding=!0),this._setInitAttr(0),this.handles[1]&&(this.options.doubleSided=!0,this.$handle2=this.handles.eq(1),this.$input2=this.inputs.length>1?this.inputs.eq(1):t("#"+this.$handle2.attr("aria-controls")),this.inputs[1]||(this.inputs=this.inputs.add(this.$input2)),e=!0,this._setInitAttr(1)),this.setHandles(),this._events()}},{key:"setHandles",value:function(){var t=this;this.handles[1]?this._setHandlePos(this.$handle,this.inputs.eq(0).val(),!0,function(){t._setHandlePos(t.$handle2,t.inputs.eq(1).val(),!0)}):this._setHandlePos(this.$handle,this.inputs.eq(0).val(),!0)}},{key:"_reflow",value:function(){this.setHandles()}},{key:"_pctOfBar",value:function(t){var i=e(t-this.options.start,this.options.end-this.options.start);switch(this.options.positionValueFunction){case"pow":i=this._logTransform(i);break;case"log":i=this._powTransform(i)}return i.toFixed(2)}},{key:"_value",value:function(t){switch(this.options.positionValueFunction){case"pow":t=this._powTransform(t);break;case"log":t=this._logTransform(t)}var e=(this.options.end-this.options.start)*t+this.options.start;return e}},{key:"_logTransform",value:function(t){return s(this.options.nonLinearBase,t*(this.options.nonLinearBase-1)+1)}},{key:"_powTransform",value:function(t){return(Math.pow(this.options.nonLinearBase,t)-1)/(this.options.nonLinearBase-1)}},{key:"_setHandlePos",value:function(t,i,s,n){if(!this.$element.hasClass(this.options.disabledClass)){i=parseFloat(i),i<this.options.start?i=this.options.start:i>this.options.end&&(i=this.options.end);var a=this.options.doubleSided;if(a)if(0===this.handles.index(t)){var o=parseFloat(this.$handle2.attr("aria-valuenow"));i=i>=o?o-this.options.step:i}else{var l=parseFloat(this.$handle.attr("aria-valuenow"));i=i<=l?l+this.options.step:i}this.options.vertical&&!s&&(i=this.options.end-i);var r=this,d=this.options.vertical,h=d?"height":"width",u=d?"top":"left",p=t[0].getBoundingClientRect()[h],f=this.$element[0].getBoundingClientRect()[h],c=this._pctOfBar(i),v=(f-p)*c,g=(100*e(v,f)).toFixed(this.options.decimal);i=parseFloat(i.toFixed(this.options.decimal));var _={};if(this._setValues(t,i),a){var m,$=0===this.handles.index(t),F=~~(100*e(p,f));if($)_[u]=g+"%",m=parseFloat(this.$handle2[0].style[u])-g+F,n&&"function"==typeof n&&n();else{var y=parseFloat(this.$handle[0].style[u]);m=g-(isNaN(y)?(this.options.initialStart-this.options.start)/((this.options.end-this.options.start)/100):y)+F}_["min-"+h]=m+"%"}this.$element.one("finished.zf.animate",function(){r.$element.trigger("moved.zf.slider",[t])});var R=this.$element.data("dragging")?1e3/60:this.options.moveTime;Foundation.Move(R,t,function(){isNaN(g)?t.css(u,100*c+"%"):t.css(u,g+"%"),r.options.doubleSided?r.$fill.css(_):r.$fill.css(h,100*c+"%")}),clearTimeout(r.timeout),r.timeout=setTimeout(function(){r.$element.trigger("changed.zf.slider",[t])},r.options.changedDelay)}}},{key:"_setInitAttr",value:function(t){var e=0===t?this.options.initialStart:this.options.initialEnd,i=this.inputs.eq(t).attr("id")||Foundation.GetYoDigits(6,"slider");this.inputs.eq(t).attr({id:i,max:this.options.end,min:this.options.start,step:this.options.step}),this.inputs.eq(t).val(e),this.handles.eq(t).attr({role:"slider","aria-controls":i,"aria-valuemax":this.options.end,"aria-valuemin":this.options.start,"aria-valuenow":e,"aria-orientation":this.options.vertical?"vertical":"horizontal",tabindex:0})}},{key:"_setValues",value:function(t,e){var i=this.options.doubleSided?this.handles.index(t):0;this.inputs.eq(i).val(e),t.attr("aria-valuenow",e)}},{key:"_handleEvent",value:function(s,n,a){var o,l;if(a)o=this._adjustValue(null,a),l=!0;else{s.preventDefault();var r=this,d=this.options.vertical,h=d?"height":"width",u=d?"top":"left",p=d?s.pageY:s.pageX,f=(this.$handle[0].getBoundingClientRect()[h]/2,this.$element[0].getBoundingClientRect()[h]),c=d?t(window).scrollTop():t(window).scrollLeft(),v=this.$element.offset()[u];s.clientY===s.pageY&&(p+=c);var g,_=p-v;g=_<0?0:_>f?f:_;var m=e(g,f);if(o=this._value(m),Foundation.rtl()&&!this.options.vertical&&(o=this.options.end-o),o=r._adjustValue(null,o),l=!1,!n){var $=i(this.$handle,u,g,h),F=i(this.$handle2,u,g,h);n=$<=F?this.$handle:this.$handle2}}this._setHandlePos(n,o,l)}},{key:"_adjustValue",value:function(t,e){var i,s,n,a,o=this.options.step,l=parseFloat(o/2);return i=t?parseFloat(t.attr("aria-valuenow")):e,s=i%o,n=i-s,a=n+o,0===s?i:i=i>=n+l?a:n}},{key:"_events",value:function(){this._eventsForHandle(this.$handle),this.handles[1]&&this._eventsForHandle(this.$handle2)}},{key:"_eventsForHandle",value:function(e){var i,s=this;if(this.inputs.off("change.zf.slider").on("change.zf.slider",function(e){var i=s.inputs.index(t(this));s._handleEvent(e,s.handles.eq(i),t(this).val())}),this.options.clickSelect&&this.$element.off("click.zf.slider").on("click.zf.slider",function(e){return!s.$element.data("dragging")&&void(t(e.target).is("[data-slider-handle]")||(s.options.doubleSided?s._handleEvent(e):s._handleEvent(e,s.$handle)))}),this.options.draggable){this.handles.addTouch();var n=t("body");e.off("mousedown.zf.slider").on("mousedown.zf.slider",function(a){e.addClass("is-dragging"),s.$fill.addClass("is-dragging"),s.$element.data("dragging",!0),i=t(a.currentTarget),n.on("mousemove.zf.slider",function(t){t.preventDefault(),s._handleEvent(t,i)}).on("mouseup.zf.slider",function(t){s._handleEvent(t,i),e.removeClass("is-dragging"),s.$fill.removeClass("is-dragging"),s.$element.data("dragging",!1),n.off("mousemove.zf.slider mouseup.zf.slider")})}).on("selectstart.zf.slider touchmove.zf.slider",function(t){t.preventDefault()})}e.off("keydown.zf.slider").on("keydown.zf.slider",function(e){var i,n=t(this),a=s.options.doubleSided?s.handles.index(n):0,o=parseFloat(s.inputs.eq(a).val());Foundation.Keyboard.handleKey(e,"Slider",{decrease:function(){i=o-s.options.step},increase:function(){i=o+s.options.step},decrease_fast:function(){i=o-10*s.options.step},increase_fast:function(){i=o+10*s.options.step},handled:function(){e.preventDefault(),s._setHandlePos(n,i,!0)}})})}},{key:"destroy",value:function(){this.handles.off(".zf.slider"),this.inputs.off(".zf.slider"),this.$element.off(".zf.slider"),clearTimeout(this.timeout),Foundation.unregisterPlugin(this)}}]),n}();n.defaults={start:0,end:100,step:1,initialStart:0,initialEnd:100,binding:!1,clickSelect:!0,vertical:!1,draggable:!0,disabled:!1,doubleSided:!1,decimal:2,moveTime:200,disabledClass:"disabled",invertVertical:!1,changedDelay:500,nonLinearBase:5,positionValueFunction:"linear"},Foundation.plugin(n,"Slider")}(jQuery);
|