From 0f65a03f2009038a36bc75cbbc571421b4546ab4 Mon Sep 17 00:00:00 2001
From: Mobius1 <admin@twitchaddict.tv>
Date: Tue, 17 Apr 2018 00:22:26 +0100
Subject: [PATCH] Code reduction

---
 dist/rangeable.min.js |  2 +-
 src/index.js          | 51 +++++++++++++++++++++----------------------
 2 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/dist/rangeable.min.js b/dist/rangeable.min.js
index f202940..ac9f9bf 100644
--- a/dist/rangeable.min.js
+++ b/dist/rangeable.min.js
@@ -8,4 +8,4 @@
  * Version: 0.1.0
  *
  */
-(function(i,j){"object"==typeof exports?module.exports=j("Rangeable"):"function"==typeof define&&define.amd?define([],j):i.Rangeable=j("Rangeable")})("undefined"==typeof global?this.window||this.global:global,function(){var i=function(o,p){var q=document.createElement(o);return p&&q.classList.add(p),q},j=function(o){return o&&"function"==typeof o},m=function(o,p,q){var r;return function(){if(q=q||this,!r)return o.apply(q,arguments),r=!0,setTimeout(function(){r=!1},p)}},n=function(o,p){this.plugins=["ruler"],"string"==typeof o&&(o=document.querySelector(o)),this.input=o,this.config=Object.assign({},{type:"single",tooltips:"always",updateThrottle:30,classes:{input:"rangeable-input",container:"rangeable-container",vertical:"rangeable-vertical",progress:"rangeable-progress",handle:"rangeable-handle",tooltip:"rangeable-tooltip",track:"rangeable-track",multiple:"rangeable-multiple",disabled:"rangeable-disabled"}},p),this.mouseAxis={x:"clientX",y:"clientY"},this.trackSize={x:"width",y:"height"},this.trackPos={x:"left",y:"top"},this.lastPos=0,this.double="double"===this.config.type||Array.isArray(this.config.value),this.touch="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,this.init(),this.onInit()};return n.prototype.init=function(){if(!this.input.rangeable){var p,o={min:0,max:100,step:1,value:this.input.value};for(p in o)this.input[p]||(this.input[p]=o[p]),void 0!==this.config[p]&&(this.input[p]=this.config[p]);this.axis=this.config.vertical?"y":"x",this.input.rangeable=this,this.double?(this.input.values=this.config.value?this.config.value:[this.input.min,this.input.max],this.input.defaultValues=this.input.values.slice()):this.input.defaultValue||(this.input.defaultValue=this.input.value),this.render(),this.initialised=!0}},n.prototype.render=function(){var o=this,p=this.config,q=p.classes,r=i("div",q.container),s=i("div",q.track),t=i("div",q.progress),u=i("div",q.handle),v=i("div",q.tooltip);if(this.double?(u=[i("div",q.handle),i("div",q.handle)],v=[i("div",q.tooltip),i("div",q.tooltip),i("div",q.tooltip)],u.forEach(function(x,y){x.index=y,t.appendChild(x),x.appendChild(v[y]),x.tabIndex=1,p.handles&&p.handles[y]&&p.handles[y].locked&&!0===p.handles[y].locked&&(x.locked=!0)}),this.input.tabIndex=-1,p.vertical&&t.appendChild(u[0]),t.appendChild(v[2]),r.classList.add(q.multiple)):(t.appendChild(u),u.appendChild(v),p.handle&&p.handle.locked&&!0===p.handle.locked&&(u.locked=!0)),r.appendChild(s),p.vertical&&r.classList.add(q.vertical),p.size&&(r.style[this.trackSize[this.axis]]=isNaN(p.size)?p.size:p.size+"px"),p.tooltips&&(r.classList.add("has-tooltip"),"string"==typeof p.tooltips&&"always"===p.tooltips&&r.classList.add("show-tooltip")),this.nodes={container:r,track:s,progress:t,handle:u,tooltip:v},!this.double)p.handle&&void 0!==p.handle.min&&void 0!==p.handle.max&&(u=i("div","rangeable-buffer"),s.appendChild(u),this.nodes.buffer=u,this.limits={min:p.handle.min,max:p.handle.max});else if(p.handles){this.nodes.buffers=[],this.limits=[];var w=i("div","rangeable-buffers");p.handles.forEach(function(x,y){if(void 0!==x.min&&void 0!==x.max){var z=i("div","rangeable-buffer");w.appendChild(z),o.nodes.buffers.push(z),o.limits[y]={min:x.min,max:x.max}}}),s.appendChild(w)}s.appendChild(t),this.input.parentNode.insertBefore(r,this.input),r.insertBefore(this.input,s),this.input.classList.add(q.input),this.bind(),this.update()},n.prototype.reset=function(){this.double?this.input.defaultValues.forEach(this.setValue,this):this.setValue(this.input.defaultValue),this.onEnd()},n.prototype.setValueFromPosition=function(o){var p=parseFloat(this.input.min),q=parseFloat(this.input.max),r=parseFloat(this.input.step),s=this.touch?o.touches[0][this.mouseAxis[this.axis]]:o[this.mouseAxis[this.axis]],t=s-this.rects.container[this.trackPos[this.axis]],u=this.rects.container[this.trackSize[this.axis]];return"mousedown"===o.type&&(!this.double&&this.nodes.handle.contains(o.target)||this.double&&(this.nodes.handle[0].contains(o.target)||this.nodes.handle[1].contains(o.target)))?!1:(o=Math.ceil(((this.config.vertical?100*((u-t)/u):100*(t/u))*(q-p)/100+p)/r)*r,s>=this.lastPos&&(o-=r),parseFloat(o)!==parseFloat(this.startValue)&&void(r=!1,this.double&&(r=this.activeHandle.index),o=this.limit(o,r),this.setValue(o,r)))},n.prototype.start=function(o){return o.preventDefault(),this.startValue=this.getValue(),this.onStart(),this.nodes.container.classList.add("dragging"),this.recalculate(),this.activeHandle=this.getHandle(o),!!this.activeHandle&&void(this.activeHandle.classList.add("active"),this.setValueFromPosition(o),this.touch?(document.addEventListener("touchmove",this.events.move,!1),document.addEventListener("touchend",this.events.stop,!1),document.addEventListener("touchcancel",this.events.stop,!1)):(document.addEventListener("mousemove",this.events.move,!1),document.addEventListener("mouseup",this.events.stop,!1)))},n.prototype.move=function(o){this.setValueFromPosition(o),this.lastPos=this.touch?o.touches[0][this.mouseAxis[this.axis]]:o[this.mouseAxis[this.axis]]},n.prototype.stop=function(){this.stopValue=this.getValue(),this.nodes.container.classList.remove("dragging"),this.onEnd(),this.activeHandle.classList.remove("active"),this.activeHandle=!1,this.touch?(document.removeEventListener("touchmove",this.events.move),document.removeEventListener("touchend",this.events.stop),document.removeEventListener("touchcancel",this.events.stop)):(document.removeEventListener("mousemove",this.events.move),document.removeEventListener("mouseup",this.events.stop)),this.startValue!==this.stopValue&&this.input.dispatchEvent(new Event("change")),this.startValue=null},n.prototype.keydown=function(o){var p=this;this.double&&this.nodes.handle.forEach(function(q){if(q===document.activeElement)switch(o.key){case"ArrowRight":case"ArrowUp":p.stepUp(q.index);break;case"ArrowLeft":case"ArrowDown":p.stepDown(q.index);}})},n.prototype.stepUp=function(o){var p=parseFloat(this.input.step),q=this.getValue();this.double&&void 0!==o&&(q=q[o]),p=this.limit(parseFloat(q)+p,o),this.setValue(p,o)},n.prototype.stepDown=function(o){var p=parseFloat(this.input.step),q=this.getValue();this.double&&void 0!==o&&(q=q[o]),p=this.limit(parseFloat(q)-p,o),this.setValue(p,o)},n.prototype.limit=function(o,p){var q=this.input,r=parseFloat(q.min),s=parseFloat(q.max);return this.getValue(),this.double&&void 0!==p?(!p&&o>=q.values[1]?o=q.values[1]:p&&o<=q.values[0]&&(o=q.values[0]),this.limits)&&(p?o>this.limits[1].max?o=this.limits[1].max:o<this.limits[1].min&&(o=this.limits[1].min):o>this.limits[0].max?o=this.limits[0].max:o<this.limits[0].min&&(o=this.limits[0].min)):this.limits&&(o>this.limits.max?o=this.limits.max:o<this.limits.min&&(o=this.limits.min)),o>=s?o=s:o<=r&&(o=r),o},n.prototype.recalculate=function(){var o=[];this.double?this.nodes.handle.forEach(function(p,q){o[q]=p.getBoundingClientRect()}):o=this.nodes.handle.getBoundingClientRect(),this.rects={handle:o,container:this.nodes.container.getBoundingClientRect()}},n.prototype.update=function(){var o=this;this.recalculate(),this.accuracy=0,this.input.step.includes(".")&&(this.accuracy=(this.input.step.split(".")[1]||[]).length);var p=this.rects.container[this.trackSize[this.axis]];if(this.double)this.config.handles&&this.nodes.buffers&&this.config.handles.forEach(function(s,t){var u=o.nodes.buffers[t],v=s.min/o.input.max*p;u.style[o.config.vertical?"bottom":"left"]=v+"px",u.style[o.trackSize[o.axis]]=s.max/o.input.max*p-v+"px"});else if(this.config.handle){var q=this.nodes.buffer,r=this.config.handle.min/this.input.max*p;q.style.left=r+"px",q.style.width=this.config.handle.max/this.input.max*p-r+"px"}q=this.getValue(),this.double?this.input.values.forEach(function(s,t){o.setValue(o.limit(s,t),t)}):this.setValue(this.limit(q))},n.prototype.getValue=function(){return this.double?this.input.values:this.input.value},n.prototype.parseValue=function(o){var p=parseFloat(this.input.min),q=parseFloat(this.input.max);return void 0===o&&(o=this.input.value),o=parseFloat(o),o=o.toFixed(this.accuracy),o<p?o=p.toFixed(this.accuracy):o>q&&(o=q.toFixed(this.accuracy)),o},n.prototype.setValue=function(o,p){var q=this.nodes;if(o=this.parseValue(o),this.double&&void 0===p)return!1;var r=this.initialised&&(o!==this.input.value||this.nativeEvent);if(this.double){var s=this.input.values;if(s[p]=o,this.config.tooltips){q.tooltip[p].textContent=o;var t=q.tooltip[0].getBoundingClientRect(),u=q.tooltip[1].getBoundingClientRect();t=!(t.right<u.left||t.left>u.right||t.bottom<u.top||t.top>u.bottom),q.container.classList.toggle("combined-tooltip",t),t&&(q.tooltip[2].textContent=s[0]===s[1]?s[0]:s[0]+" - "+s[1])}}else this.input.value=o,q.tooltip.textContent=o;this.setPosition(o,p),r&&(this.onChange(),this.nativeEvent||this.input.dispatchEvent(new Event("input")),this.nativeEvent=!1)},n.prototype.native=function(){this.nativeEvent=!0,this.setValue()},n.prototype.setPosition=function(o){if(this.double){o=this.getPosition(this.input.values[0]);var p=this.getPosition(this.input.values[1]);this.nodes.progress.style[this.config.vertical?"bottom":"left"]=o+"px",o=p-o}else o=this.getPosition();this.nodes.progress.style[this.trackSize[this.axis]]=o+"px"},n.prototype.getPosition=function(o){void 0===o&&(o=this.input.value);var p=parseFloat(this.input.min),q=parseFloat(this.input.max);return(o-p)/(q-p)*this.rects.container[this.trackSize[this.axis]]},n.prototype.getHandle=function(o){if(!this.double)return!this.nodes.handle.locked&&this.nodes.handle;var p=this.rects,q=Math.abs(o[this.mouseAxis[this.axis]]-p.handle[0][this.trackPos[this.axis]]);return p=Math.abs(o[this.mouseAxis[this.axis]]-p.handle[1][this.trackPos[this.axis]]),(o=o.target.closest("."+this.config.classes.handle))||(o=q>p?this.nodes.handle[1]:this.nodes.handle[0]),!o.locked&&o},n.prototype.onInit=function(){j(this.config.onInit)&&this.config.onInit.call(this,this.getValue())},n.prototype.onStart=function(){j(this.config.onStart)&&this.config.onStart.call(this,this.getValue())},n.prototype.onChange=function(){j(this.config.onChange)&&this.config.onChange.call(this,this.getValue())},n.prototype.onEnd=function(){j(this.config.onEnd)&&this.config.onEnd.call(this,this.getValue())},n.prototype.enable=function(){this.disabled&&(this.touch?this.nodes.container.addEventListener("touchstart",this.events.touchstart):this.nodes.container.addEventListener("mousedown",this.events.down),this.nodes.container.classList.remove(this.config.classes.disabled),this.disabled=!1)},n.prototype.disable=function(){this.disabled||(this.touch?this.nodes.container.removeEventListener("touchstart",this.events.touchstart):this.nodes.container.removeEventListener("mousedown",this.events.down),this.nodes.container.classList.add(this.config.classes.disabled),this.disabled=!0)},n.prototype.bind=function(){this.events={start:this.start.bind(this),move:this.move.bind(this),stop:this.stop.bind(this),update:this.update.bind(this),reset:this.reset.bind(this),set:this.native.bind(this),key:this.keydown.bind(this)},this.events.scroll=m(this.events.update,this.config.updateThrottle),this.events.resize=m(this.events.update,this.config.updateThrottle),document.addEventListener("scroll",this.events.scroll,!1),window.addEventListener("resize",this.events.resize,!1),this.double&&document.addEventListener("keydown",this.events.key,!1),this.nodes.container.addEventListener(this.touch?"touchstart":"mousedown",this.events.start,!1),this.input.addEventListener("input",this.events.set,!1),this.input.form&&this.input.form.addEventListener("reset",this.events.reset,!1)},n.prototype.unbind=function(){document.removeEventListener("scroll",this.events.scroll),window.removeEventListener("resize",this.events.resize),this.double&&document.removeEventListener("keydown",this.events.key),this.nodes.container.removeEventListener(this.touch?"touchstart":"mousedown",void 0),this.input.removeEventListener("input",this.events.set),this.input.form&&this.input.form.removeEventListener("reset",this.events.reset),this.events=null},n.prototype.destroy=function(){this.input.rangeable&&(this.unbind(),this.input.classList.remove(this.config.classes.input),this.nodes.container.parentNode.replaceChild(this.input,this.nodes.container),delete this.input.rangeable,this.initialised=!1)},n});
\ No newline at end of file
+(function(i,j){"object"==typeof exports?module.exports=j("Rangeable"):"function"==typeof define&&define.amd?define([],j):i.Rangeable=j("Rangeable")})("undefined"==typeof global?this.window||this.global:global,function(){var i=function(o,p){var q=document.createElement(o);return p&&q.classList.add(p),q},j=function(o){return o&&"function"==typeof o},m=function(o,p,q){var r;return function(){if(q=q||this,!r)return o.apply(q,arguments),r=!0,setTimeout(function(){r=!1},p)}},n=function(o,p){this.plugins=["ruler"],"string"==typeof o&&(o=document.querySelector(o)),this.input=o,this.config=Object.assign({},{type:"single",tooltips:"always",updateThrottle:30,classes:{input:"rangeable-input",container:"rangeable-container",vertical:"rangeable-vertical",progress:"rangeable-progress",handle:"rangeable-handle",tooltip:"rangeable-tooltip",track:"rangeable-track",multiple:"rangeable-multiple",disabled:"rangeable-disabled"}},p),this.mouseAxis={x:"clientX",y:"clientY"},this.trackSize={x:"width",y:"height"},this.trackPos={x:"left",y:"top"},this.lastPos=0,this.double="double"===this.config.type||Array.isArray(this.config.value),this.touch="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,this.init(),this.onInit()};return n.prototype.init=function(){if(!this.input.rangeable){var p,o={min:0,max:100,step:1,value:this.input.value};for(p in o)this.input[p]||(this.input[p]=o[p]),void 0!==this.config[p]&&(this.input[p]=this.config[p]);this.axis=this.config.vertical?"y":"x",this.input.rangeable=this,this.double?(this.input.values=this.config.value?this.config.value:[this.input.min,this.input.max],this.input.defaultValues=this.input.values.slice()):this.input.defaultValue||(this.input.defaultValue=this.input.value),this.render(),this.initialised=!0}},n.prototype.render=function(){var o=this,p=this.config,q=p.classes,r=i("div",q.container),s=i("div",q.track),t=i("div",q.progress),u=i("div",q.handle),v=i("div",q.tooltip);if(this.double?(u=[i("div",q.handle),i("div",q.handle)],v=[i("div",q.tooltip),i("div",q.tooltip),i("div",q.tooltip)],u.forEach(function(x,y){x.index=y,t.appendChild(x),x.appendChild(v[y]),x.tabIndex=1,p.handles&&p.handles[y]&&p.handles[y].locked&&!0===p.handles[y].locked&&(x.locked=!0)}),this.input.tabIndex=-1,p.vertical&&t.appendChild(u[0]),t.appendChild(v[2]),r.classList.add(q.multiple)):(t.appendChild(u),u.appendChild(v),p.handle&&p.handle.locked&&!0===p.handle.locked&&(u.locked=!0)),r.appendChild(s),p.vertical&&r.classList.add(q.vertical),p.size&&(r.style[this.trackSize[this.axis]]=isNaN(p.size)?p.size:p.size+"px"),p.tooltips&&(r.classList.add("has-tooltip"),"string"==typeof p.tooltips&&"always"===p.tooltips&&r.classList.add("show-tooltip")),this.nodes={container:r,track:s,progress:t,handle:u,tooltip:v},!this.double)p.handle&&void 0!==p.handle.min&&void 0!==p.handle.max&&(u=i("div","rangeable-buffer"),s.appendChild(u),this.nodes.buffer=u,this.limits={min:p.handle.min,max:p.handle.max});else if(p.handles){this.nodes.buffers=[],this.limits=[];var w=i("div","rangeable-buffers");p.handles.forEach(function(x,y){if(void 0!==x.min&&void 0!==x.max){var z=i("div","rangeable-buffer");w.appendChild(z),o.nodes.buffers.push(z),o.limits[y]={min:x.min,max:x.max}}}),s.appendChild(w)}s.appendChild(t),this.input.parentNode.insertBefore(r,this.input),r.insertBefore(this.input,s),this.input.classList.add(q.input),this.bind(),this.update()},n.prototype.reset=function(){this.double?this.input.defaultValues.forEach(this.setValue,this):this.setValue(this.input.defaultValue),this.onEnd()},n.prototype.setValueFromPosition=function(o){var p=parseFloat(this.input.min),q=parseFloat(this.input.max),r=parseFloat(this.input.step),s=this.touch?o.touches[0][this.mouseAxis[this.axis]]:o[this.mouseAxis[this.axis]],t=s-this.rects.container[this.trackPos[this.axis]],u=this.rects.container[this.trackSize[this.axis]];return"mousedown"===o.type&&(!this.double&&this.nodes.handle.contains(o.target)||this.double&&(this.nodes.handle[0].contains(o.target)||this.nodes.handle[1].contains(o.target)))?!1:(o=Math.ceil(((this.config.vertical?100*((u-t)/u):100*(t/u))*(q-p)/100+p)/r)*r,s>=this.lastPos&&(o-=r),parseFloat(o)!==parseFloat(this.startValue)&&void(r=!1,this.double&&(r=this.activeHandle.index),o=this.limit(o,r),this.setValue(o,r)))},n.prototype.start=function(o){return o.preventDefault(),this.startValue=this.getValue(),this.onStart(),this.nodes.container.classList.add("dragging"),this.recalculate(),this.activeHandle=this.getHandle(o),!!this.activeHandle&&void(this.activeHandle.classList.add("active"),this.setValueFromPosition(o),this.touch?(document.addEventListener("touchmove",this.events.move,!1),document.addEventListener("touchend",this.events.stop,!1),document.addEventListener("touchcancel",this.events.stop,!1)):(document.addEventListener("mousemove",this.events.move,!1),document.addEventListener("mouseup",this.events.stop,!1)))},n.prototype.move=function(o){this.setValueFromPosition(o),this.lastPos=this.touch?o.touches[0][this.mouseAxis[this.axis]]:o[this.mouseAxis[this.axis]]},n.prototype.stop=function(){this.stopValue=this.getValue(),this.nodes.container.classList.remove("dragging"),this.onEnd(),this.activeHandle.classList.remove("active"),this.activeHandle=!1,this.touch?(document.removeEventListener("touchmove",this.events.move),document.removeEventListener("touchend",this.events.stop),document.removeEventListener("touchcancel",this.events.stop)):(document.removeEventListener("mousemove",this.events.move),document.removeEventListener("mouseup",this.events.stop)),this.startValue!==this.stopValue&&this.input.dispatchEvent(new Event("change")),this.startValue=null},n.prototype.keydown=function(o){var p=this;this.double&&this.nodes.handle.forEach(function(q){if(q===document.activeElement)switch(o.key){case"ArrowRight":case"ArrowUp":p.stepUp(q.index);break;case"ArrowLeft":case"ArrowDown":p.stepDown(q.index);}})},n.prototype.stepUp=function(o){var p=parseFloat(this.input.step),q=this.getValue();this.double&&void 0!==o&&(q=q[o]),p=this.limit(parseFloat(q)+p,o),this.setValue(p,o)},n.prototype.stepDown=function(o){var p=parseFloat(this.input.step),q=this.getValue();this.double&&void 0!==o&&(q=q[o]),p=this.limit(parseFloat(q)-p,o),this.setValue(p,o)},n.prototype.limit=function(o,p){var q=this.input,r=parseFloat(q.min),s=parseFloat(q.max);return this.double&&void 0!==p?(!p&&o>q.values[1]?o=q.values[1]:p&&o<q.values[0]&&(o=q.values[0]),this.limits)&&(p?o>this.limits[1].max?o=this.limits[1].max:o<this.limits[1].min&&(o=this.limits[1].min):o>this.limits[0].max?o=this.limits[0].max:o<this.limits[0].min&&(o=this.limits[0].min)):this.limits&&(o>this.limits.max?o=this.limits.max:o<this.limits.min&&(o=this.limits.min)),o>s?o=s:o<r&&(o=r),o},n.prototype.recalculate=function(){var o=[];this.double?this.nodes.handle.forEach(function(p,q){o[q]=p.getBoundingClientRect()}):o=this.nodes.handle.getBoundingClientRect(),this.rects={handle:o,container:this.nodes.container.getBoundingClientRect()}},n.prototype.update=function(){var o=this;this.recalculate(),this.accuracy=0,this.input.step.includes(".")&&(this.accuracy=(this.input.step.split(".")[1]||[]).length);var p=this.getValue(),q=this.rects.container[this.trackSize[this.axis]],r=function(s,t,u){s.style[o.config.vertical?"bottom":"left"]=t+"px",s.style[o.trackSize[o.axis]]=u/o.input.max*q-t+"px"};this.double?(this.config.handles&&this.nodes.buffers&&this.config.handles.forEach(function(s,t){r(o.nodes.buffers[t],s.min/o.input.max*q,s.max)}),this.input.values.forEach(function(s,t){o.setValue(o.limit(s,t),t)})):(this.config.handle&&r(this.nodes.buffer,this.config.handle.min/this.input.max*q,this.config.handle.max),this.setValue(this.limit(p)))},n.prototype.getValue=function(){return this.double?this.input.values:this.input.value},n.prototype.parseValue=function(o){var p=parseFloat(this.input.min),q=parseFloat(this.input.max);return void 0===o&&(o=this.input.value),o=parseFloat(o),o=o.toFixed(this.accuracy),o<p?o=p.toFixed(this.accuracy):o>q&&(o=q.toFixed(this.accuracy)),o},n.prototype.setValue=function(o,p){var q=this.nodes;if(o=this.parseValue(o),this.double&&void 0===p)return!1;var r=this.initialised&&(o!==this.input.value||this.nativeEvent);if(this.double){var s=this.input.values;if(s[p]=o,this.config.tooltips){q.tooltip[p].textContent=o;var t=q.tooltip[0].getBoundingClientRect(),u=q.tooltip[1].getBoundingClientRect();t=!(t.right<u.left||t.left>u.right||t.bottom<u.top||t.top>u.bottom),q.container.classList.toggle("combined-tooltip",t),t&&(q.tooltip[2].textContent=s[0]===s[1]?s[0]:s[0]+" - "+s[1])}}else this.input.value=o,q.tooltip.textContent=o;this.setPosition(o,p),r&&(this.onChange(),this.nativeEvent||this.input.dispatchEvent(new Event("input")),this.nativeEvent=!1)},n.prototype.native=function(){this.nativeEvent=!0,this.setValue()},n.prototype.setPosition=function(o){if(this.double){o=this.getPosition(this.input.values[0]);var p=this.getPosition(this.input.values[1]);this.nodes.progress.style[this.config.vertical?"bottom":"left"]=o+"px",o=p-o}else o=this.getPosition();this.nodes.progress.style[this.trackSize[this.axis]]=o+"px"},n.prototype.getPosition=function(o){void 0===o&&(o=this.input.value);var p=parseFloat(this.input.min),q=parseFloat(this.input.max);return(o-p)/(q-p)*this.rects.container[this.trackSize[this.axis]]},n.prototype.getHandle=function(o){if(!this.double)return!this.nodes.handle.locked&&this.nodes.handle;var p=this.rects,q=Math.abs(o[this.mouseAxis[this.axis]]-p.handle[0][this.trackPos[this.axis]]);return p=Math.abs(o[this.mouseAxis[this.axis]]-p.handle[1][this.trackPos[this.axis]]),(o=o.target.closest("."+this.config.classes.handle))||(o=q>p?this.nodes.handle[1]:this.nodes.handle[0]),!o.locked&&o},n.prototype.onInit=function(){j(this.config.onInit)&&this.config.onInit.call(this,this.getValue())},n.prototype.onStart=function(){j(this.config.onStart)&&this.config.onStart.call(this,this.getValue())},n.prototype.onChange=function(){j(this.config.onChange)&&this.config.onChange.call(this,this.getValue())},n.prototype.onEnd=function(){j(this.config.onEnd)&&this.config.onEnd.call(this,this.getValue())},n.prototype.enable=function(){this.disabled&&(this.touch?this.nodes.container.addEventListener("touchstart",this.events.touchstart):this.nodes.container.addEventListener("mousedown",this.events.down),this.nodes.container.classList.remove(this.config.classes.disabled),this.disabled=!1)},n.prototype.disable=function(){this.disabled||(this.touch?this.nodes.container.removeEventListener("touchstart",this.events.touchstart):this.nodes.container.removeEventListener("mousedown",this.events.down),this.nodes.container.classList.add(this.config.classes.disabled),this.disabled=!0)},n.prototype.bind=function(){this.events={start:this.start.bind(this),move:this.move.bind(this),stop:this.stop.bind(this),update:this.update.bind(this),reset:this.reset.bind(this),set:this.native.bind(this),key:this.keydown.bind(this)},this.events.scroll=m(this.events.update,this.config.updateThrottle),this.events.resize=m(this.events.update,this.config.updateThrottle),document.addEventListener("scroll",this.events.scroll,!1),window.addEventListener("resize",this.events.resize,!1),this.double&&document.addEventListener("keydown",this.events.key,!1),this.nodes.container.addEventListener(this.touch?"touchstart":"mousedown",this.events.start,!1),this.input.addEventListener("input",this.events.set,!1),this.input.form&&this.input.form.addEventListener("reset",this.events.reset,!1)},n.prototype.unbind=function(){document.removeEventListener("scroll",this.events.scroll),window.removeEventListener("resize",this.events.resize),this.double&&document.removeEventListener("keydown",this.events.key),this.nodes.container.removeEventListener(this.touch?"touchstart":"mousedown",void 0),this.input.removeEventListener("input",this.events.set),this.input.form&&this.input.form.removeEventListener("reset",this.events.reset),this.events=null},n.prototype.destroy=function(){this.input.rangeable&&(this.unbind(),this.input.classList.remove(this.config.classes.input),this.nodes.container.parentNode.replaceChild(this.input,this.nodes.container),delete this.input.rangeable,this.initialised=!1)},n});
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index 235393f..9545a49 100644
--- a/src/index.js
+++ b/src/index.js
@@ -527,14 +527,13 @@
 	 */
 	Rangeable.prototype.limit = function(value, index) {
 		const el = this.input;
-		let min = parseFloat(el.min);
-		let max = parseFloat(el.max);
-		let inval = this.getValue();
+		const min = parseFloat(el.min);
+		const max = parseFloat(el.max);
 
 		if ( this.double && index !== undefined ) {
-			if (!index && value >= el.values[1]) {
+			if (!index && value > el.values[1]) {
 				value = el.values[1];
-			} else if (index && value <= el.values[0]) {
+			} else if (index && value < el.values[0]) {
 				value = el.values[0];
 			}
 
@@ -555,17 +554,17 @@
 			}
 		} else {
 			if ( this.limits ) {
-					if ( value > this.limits.max ) {
-						value = this.limits.max;
-					} else if ( value < this.limits.min ) {
-						value = this.limits.min;
-					}
+				if ( value > this.limits.max ) {
+					value = this.limits.max;
+				} else if ( value < this.limits.min ) {
+					value = this.limits.min;
+				}
 			}
 		}
 
-		if ( value >= max ) {
+		if ( value > max ) {
 			value = max;
-		} else if ( value <= min ) {
+		} else if ( value < min ) {
 			value = min;
 		}
 
@@ -607,31 +606,31 @@
 			this.accuracy = (this.input.step.split(".")[1] || []).length;
 		}
 
+		const value = this.getValue();
+
 		const size = this.rects.container[this.trackSize[this.axis]];
+
+		const setBuffer = (el, offset, max) => {
+			el.style[this.config.vertical ? "bottom" : "left"] = `${offset}px`;
+			el.style[this.trackSize[this.axis]] = `${(max / this.input.max * size) - offset}px`;
+		};
+
 		if ( this.double ) {
+			// set buffers
 			if ( this.config.handles && this.nodes.buffers ) {
 				this.config.handles.forEach((obj, i) => {
-					const buffer = this.nodes.buffers[i];
-					const offset = obj.min / this.input.max * size;
-					buffer.style[this.config.vertical ? "bottom" : "left"] = `${offset}px`;
-					buffer.style[this.trackSize[this.axis]] = `${(obj.max / this.input.max * size) - offset}px`;
+					setBuffer(this.nodes.buffers[i], (obj.min / this.input.max * size), obj.max);
 				});
 			}
-		} else {
-			if ( this.config.handle ) {
-					const buffer = this.nodes.buffer;
-					const offset = this.config.handle.min / this.input.max * size;
-					buffer.style.left = `${offset}px`;
-					buffer.style.width = `${(this.config.handle.max / this.input.max * size) - offset}px`;
-			}
-		}
 
-		const value = this.getValue();
-		if (this.double) {
 			this.input.values.forEach((val, i) => {
 				this.setValue(this.limit(val, i), i);
 			});
 		} else {
+			// set buffer
+			if ( this.config.handle ) {
+				setBuffer(this.nodes.buffer, (this.config.handle.min / this.input.max * size), this.config.handle.max);
+			}
 			this.setValue(this.limit(value));
 		}
 	}