diff --git a/.gitignore b/.gitignore index 3c3629e..e6fde19 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +.idea/ +.directory \ No newline at end of file diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 7cb63b1..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -rangeSlider \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index d821048..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 8662aa9..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index e6a254f..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/rangeSlider.iml b/.idea/rangeSlider.iml deleted file mode 100644 index 1b66a81..0000000 --- a/.idea/rangeSlider.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/dist/rangeSlider.js b/dist/rangeSlider.js index 5a167cc..21c1d6b 100644 --- a/dist/rangeSlider.js +++ b/dist/rangeSlider.js @@ -270,7 +270,7 @@ if (!isString(name)) { throw new TypeError('event name must be String'); } - if (!el instanceof HTMLElement) { + if (!(el instanceof HTMLElement)) { throw new TypeError('element must be HTMLElement'); } name = name.trim(); @@ -361,7 +361,7 @@ * @this {Object} event name */ function rm(listener) { - if(listener === instance._startEventListener){ + if (listener === instance._startEventListener) { this.el.removeEventListener(this.eventName, listener, false); } } @@ -603,7 +603,7 @@ // Ok we're done fire the change event triggerEvent(this.element, 'change', {origin: this.identifier}); - if(this.isInteractsNow || this.needTriggerEvents){ + if (this.isInteractsNow || this.needTriggerEvents) { if (this.onSlideEnd && typeof this.onSlideEnd === 'function') { this.onSlideEnd(this.value, this.percent, this.position); } @@ -639,7 +639,7 @@ this.value = value; this._updatePercentFromValue(); - if(this.isInteractsNow || this.needTriggerEventss){ + if (this.isInteractsNow || this.needTriggerEventss) { if (this.onSlideStart && typeof this.onSlideStart === 'function' && this.onSlideEventsCount === 0) { this.onSlideStart(this.value, this.percent, this.position); } @@ -766,7 +766,7 @@ * @returns {Plugin} */ Plugin.prototype.update = function (obj, triggerEvents) { - if(triggerEvents){ + if (triggerEvents) { this.needTriggerEvents = true; } if (isObject(obj)) { diff --git a/dist/rangeSlider.min.css b/dist/rangeSlider.min.css index db26854..56bc853 100644 --- a/dist/rangeSlider.min.css +++ b/dist/rangeSlider.min.css @@ -1 +1 @@ -.rangeSlider,.rangeSlider__fill{background:#7f8c8d;display:block;height:20px;width:100%;-webkit-box-shadow:inset 0 1px 3px rgba(0,0,0,.3);-moz-box-shadow:inset 0 1px 3px rgba(0,0,0,.3);box-shadow:inset 0 1px 3px rgba(0,0,0,.3);-webkit-border-radius:10px;-moz-border-radius:10px;-ms-border-radius:10px;-o-border-radius:10px;border-radius:10px}.rangeSlider{position:relative}.rangeSlider--disabled{filter:alpha(Opacity=40);opacity:.4}.rangeSlider__fill{background:#16a085;position:absolute;top:0;z-index:2}.rangeSlider__handle{background:#fff;border:1px solid #ccc;cursor:pointer;display:inline-block;width:40px;height:40px;position:absolute;top:-10px;z-index:3;background:-webkit-gradient(linear,50% 0,50% 100%,color-stop(0,rgba(255,255,255,0)),color-stop(100%,rgba(0,0,0,.1))) #fff;background:-webkit-linear-gradient(rgba(255,255,255,0),rgba(0,0,0,.1)) #fff;background:-moz-linear-gradient(rgba(255,255,255,0),rgba(0,0,0,.1)) #fff;background:-o-linear-gradient(rgba(255,255,255,0),rgba(0,0,0,.1)) #fff;background:linear-gradient(rgba(255,255,255,0),rgba(0,0,0,.1)) #fff;-webkit-box-shadow:0 0 8px rgba(0,0,0,.3);-moz-box-shadow:0 0 8px rgba(0,0,0,.3);box-shadow:0 0 8px rgba(0,0,0,.3);-webkit-border-radius:50%;-moz-border-radius:50%;-ms-border-radius:50%;-o-border-radius:50%;border-radius:50%}.rangeSlider__handle:after{content:"";display:block;width:18px;height:18px;margin:auto;position:absolute;top:0;right:0;bottom:0;left:0;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(0,rgba(0,0,0,.13)),color-stop(100%,rgba(255,255,255,0)));background-image:-webkit-linear-gradient(rgba(0,0,0,.13),rgba(255,255,255,0));background-image:-moz-linear-gradient(rgba(0,0,0,.13),rgba(255,255,255,0));background-image:-o-linear-gradient(rgba(0,0,0,.13),rgba(255,255,255,0));background-image:linear-gradient(rgba(0,0,0,.13),rgba(255,255,255,0));-webkit-border-radius:50%;-moz-border-radius:50%;-ms-border-radius:50%;-o-border-radius:50%;border-radius:50%}.rangeSlider__handle:active{background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(0,rgba(0,0,0,.1)),color-stop(100%,rgba(0,0,0,.12)));background-image:-webkit-linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.12));background-image:-moz-linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.12));background-image:-o-linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.12));background-image:linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.12))}input[type=range]:focus+.rangeSlider .rangeSlider__handle{-webkit-box-shadow:0 0 8px rgba(142,68,173,.9);-moz-box-shadow:0 0 8px rgba(142,68,173,.9);box-shadow:0 0 8px rgba(142,68,173,.9)}.rangeSlider__buffer{z-index:1;position:absolute;top:3px;height:14px;background:#2c3e50;border-radius:10px} \ No newline at end of file +.rangeSlider,.rangeSlider__fill{background:#7f8c8d;display:block;height:20px;width:100%;-webkit-box-shadow:inset 0 1px 3px rgba(0,0,0,.3);-moz-box-shadow:inset 0 1px 3px rgba(0,0,0,.3);box-shadow:inset 0 1px 3px rgba(0,0,0,.3);-webkit-border-radius:10px;-moz-border-radius:10px;-ms-border-radius:10px;-o-border-radius:10px;border-radius:10px}.rangeSlider{position:relative}.rangeSlider--disabled{filter:alpha(Opacity=40);opacity:.4}.rangeSlider__fill{background:#16a085;position:absolute;top:0;z-index:2}.rangeSlider__handle{background:#fff;border:1px solid #ccc;cursor:pointer;display:inline-block;width:40px;height:40px;position:absolute;top:-10px;z-index:3;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(0,rgba(255,255,255,0)),color-stop(100%,rgba(0,0,0,.1)));background-image:-webkit-linear-gradient(rgba(255,255,255,0),rgba(0,0,0,.1));background-image:-moz-linear-gradient(rgba(255,255,255,0),rgba(0,0,0,.1));background-image:-o-linear-gradient(rgba(255,255,255,0),rgba(0,0,0,.1));background-image:linear-gradient(rgba(255,255,255,0),rgba(0,0,0,.1));-webkit-box-shadow:0 0 8px rgba(0,0,0,.3);-moz-box-shadow:0 0 8px rgba(0,0,0,.3);box-shadow:0 0 8px rgba(0,0,0,.3);-webkit-border-radius:50%;-moz-border-radius:50%;-ms-border-radius:50%;-o-border-radius:50%;border-radius:50%}.rangeSlider__handle:after{content:"";display:block;width:18px;height:18px;margin:auto;position:absolute;top:0;right:0;bottom:0;left:0;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(0,rgba(0,0,0,.13)),color-stop(100%,rgba(255,255,255,0)));background-image:-webkit-linear-gradient(rgba(0,0,0,.13),rgba(255,255,255,0));background-image:-moz-linear-gradient(rgba(0,0,0,.13),rgba(255,255,255,0));background-image:-o-linear-gradient(rgba(0,0,0,.13),rgba(255,255,255,0));background-image:linear-gradient(rgba(0,0,0,.13),rgba(255,255,255,0));-webkit-border-radius:50%;-moz-border-radius:50%;-ms-border-radius:50%;-o-border-radius:50%;border-radius:50%}.rangeSlider__handle:active{background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(0,rgba(0,0,0,.1)),color-stop(100%,rgba(0,0,0,.12)));background-image:-webkit-linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.12));background-image:-moz-linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.12));background-image:-o-linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.12));background-image:linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.12))}input[type=range]:focus+.rangeSlider .rangeSlider__handle{-webkit-box-shadow:0 0 8px rgba(142,68,173,.9);-moz-box-shadow:0 0 8px rgba(142,68,173,.9);box-shadow:0 0 8px rgba(142,68,173,.9)}.rangeSlider__buffer{z-index:1;position:absolute;top:3px;height:14px;background:#2c3e50;border-radius:10px} \ No newline at end of file diff --git a/dist/rangeSlider.min.js b/dist/rangeSlider.min.js index d7977d3..7f6e55b 100644 --- a/dist/rangeSlider.min.js +++ b/dist/rangeSlider.min.js @@ -1 +1 @@ -!function(t){"use strict";"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?t():window.rangeSlider=t()}(function(){"use strict";function t(){var t=document.createElement("input");return t.setAttribute("type","range"),"text"!==t.type}function e(t,e){var i=Array.prototype.slice.call(arguments,2);return setTimeout(function(){return t.apply(null,i)},e)}function i(t,e){return e=e||100,function(){if(!t.debouncing){var i=Array.prototype.slice.apply(arguments);t.lastReturnVal=t.apply(window,i),t.debouncing=!0}return clearTimeout(t.debounceTimeout),t.debounceTimeout=setTimeout(function(){t.debouncing=!1},e),t.lastReturnVal}}function n(t){return!(0!==t.offsetWidth&&0!==t.offsetHeight&&t.open!==!1)}function s(t){for(var e=[],i=t.parentNode;n(i);)e.push(i),i=i.parentNode;return e}function o(t,e){function i(t){"undefined"!=typeof t.open&&(t.open=t.open?!1:!0)}var n=s(t),o=n.length,r=[],h=t[e];if(o){for(var a=0;o>a;a++)r[a]=n[a].style.display,n[a].style.display="block",n[a].style.height="0",n[a].style.overflow="hidden",n[a].style.visibility="hidden",i(n[a]);h=t[e];for(var l=0;o>l;l++)i(n[l]),n[l].style.display=r[l],n[l].style.height="",n[l].style.overflow="",n[l].style.visibility=""}return h}function r(t){return t===""+t}function h(t){return null!==t&&void 0!==t&&(r(t)&&isFinite(parseFloat(t))||isFinite(t))}function a(){if(!arguments.length)return null;for(var t=0,e=arguments.length;e>t;t++)if(h(arguments[t]))return arguments[t]}function l(t){return"[object Object]"===Object.prototype.toString.call(t)}function u(t,e){var i,n={};for(i in t)n[i]=t[i];for(i in e)n[i]=e[i];return n}function d(t,e){for(var i in e)t.style[i]=e[i];return t.style}function p(t,e){v(t,e)||(t.className+=" "+e)}function f(t,e){var i=" "+t.className.replace(/[\t\r\n]/g," ")+" ";if(v(t,e)){for(;i.indexOf(" "+e+" ")>=0;)i=i.replace(" "+e+" "," ");t.className=i.replace(/^\s+|\s+$/g,"")}}function c(t,e,i){for(i&&e(t);t.parentNode&&!e(t);)t=t.parentNode;return t}function m(t,e,i){if(!r(e))throw new TypeError("event name must be String");if(!t instanceof HTMLElement)throw new TypeError("element must be HTMLElement");e=e.trim();var n=new CustomEvent(e,i);t.dispatchEvent(n)}function v(t,e){return new RegExp(" "+e+" ").test(" "+t.className+" ")}function g(t,e){t.parentNode.insertBefore(e,t.nextSibling)}function y(t,e,i){e.forEach(function(e){t[x]||(t[x]={}),t[x][e]||(t[x][e]=[]),t.addEventListener(e,i,!1),t[x][e].indexOf(i)<0&&t[x][e].push(i)})}function _(t,e,i){e.forEach(function(e){t.removeEventListener(e,i,!1);var n;t[x]&&t[x][e]&&(n=t[x][e].indexOf(i))>-1&&t[x][e].splice(n,1)})}function b(t){function e(t){t===i._startEventListener&&this.el.removeEventListener(this.eventName,t,!1)}if(t[x]){var i=this;for(var n in t[x])t[x][n].forEach(e,{eventName:n,el:t});t[x]={}}}function E(t,e){var i,n,s;return this.element=t,this.options=u(X,e),this.polyfill=this.options.polyfill,this.onInit=this.options.onInit,this.onSlide=this.options.onSlide,this.onSlideStart=this.options.onSlideStart,this.onSlideEnd=this.options.onSlideEnd,this.onSlideEventsCount=-1,this.isInteractsNow=!1,this.needTriggerEvents=!1,!this.polyfill&&L?!1:(this.options.buffer=this.options.buffer||parseFloat(this.element.dataset.buffer),this.identifier="js-"+C+"-"+P++,this.min=a(this.options.min,parseFloat(this.element.getAttribute("min")),i=0),this.max=a(this.options.max,parseFloat(this.element.getAttribute("max")),n=S),this.value=a(this.options.value,this.element.value,parseFloat(this.element.value||this.min+(this.max-this.min)/2)),this.step=a(this.options.step,parseFloat(this.element.getAttribute("step"))||(s=1)),this.percent=null,this._updatePercentFromValue(),this.toFixed=this._toFixed(this.step),this.fill=document.createElement("div"),this.fill.className=this.options.fillClass,this.handle=document.createElement("div"),this.handle.className=this.options.handleClass,this.range=document.createElement("div"),this.range.className=this.options.rangeClass,this.range.id=this.identifier,this.range.appendChild(this.handle),this.range.appendChild(this.fill),this.options.bufferClass&&(this.buffer=document.createElement("div"),this.buffer.className=this.options.bufferClass,this.range.appendChild(this.buffer)),h(this.options.value)&&(this._setValue(this.options.value,!0),this.element.value=this.options.value),h(this.options.buffer)&&(this.element.dataset.buffer=this.options.buffer),(h(this.options.min)||i)&&this.element.setAttribute("min",""+this.min),(h(this.options.max)||n)&&this.element.setAttribute("max",""+this.max),(h(this.options.step)||s)&&this.element.setAttribute("step",""+this.step),g(this.element,this.range),d(this.element,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",opacity:"0"}),this._handleDown=this._handleDown.bind(this),this._handleMove=this._handleMove.bind(this),this._handleEnd=this._handleEnd.bind(this),this._startEventListener=this._startEventListener.bind(this),this._changeEventListener=this._changeEventListener.bind(this),this._handleResize=this._handleResize.bind(this),this._init(),window.addEventListener("resize",this._handleResize,!1),y(document,this.options.startEvent,this._startEventListener),void this.element.addEventListener("change",this._changeEventListener,!1))}var x="eventListenerList",w=new RegExp("/[\\n\\t]/","g"),S=100,N=300,F=50,C="rangeSlider",P=0,L=t(),X={polyfill:!0,rangeClass:"rangeSlider",disabledClass:"rangeSlider--disabled",fillClass:"rangeSlider__fill",bufferClass:"rangeSlider__buffer",handleClass:"rangeSlider__handle",startEvent:["mousedown","touchstart","pointerdown"],moveEvent:["mousemove","touchmove","pointermove"],endEvent:["mouseup","touchend","pointerup"],min:null,max:null,step:null,value:null,buffer:null,borderRadius:10};return E.prototype.constructor=E,E.prototype._toFixed=function(t){return(t+"").replace(".","").length-1},E.prototype._init=function(){this.onInit&&"function"==typeof this.onInit&&this.onInit(),this._update()},E.prototype._updatePercentFromValue=function(){this.percent=(this.value-this.min)/(this.max-this.min)},E.prototype._startEventListener=function(t,e){var i=this,n=t.target,s=!1;c(n,function(t){return s=t.id===i.identifier&&!v(t,i.options.disabledClass)},!0),s&&this._handleDown(t,e)},E.prototype._changeEventListener=function(t,e){if(!e||e.origin!==this.identifier){var i=t.target.value,n=this._getPositionFromValue(i);this._setPosition(n)}},E.prototype._update=function(){this.handleWidth=o(this.handle,"offsetWidth"),this.rangeWidth=o(this.range,"offsetWidth"),this.maxHandleX=this.rangeWidth-this.handleWidth,this.grabX=this.handleWidth/2,this.position=this._getPositionFromValue(this.value),this.element.disabled?p(this.range,this.options.disabledClass):f(this.range,this.options.disabledClass),this._setPosition(this.position),this.options.bufferClass&&this.options.buffer&&this._setBufferPosition(this.options.buffer),this._updatePercentFromValue(),this.element.dispatchEvent(new Event("change"))},E.prototype._handleResize=function(){var t=this;return i(function(){e(function(){t._update()},N)},F)()},E.prototype._handleDown=function(t){if(this.isInteractsNow=!0,t.preventDefault(),y(document,this.options.moveEvent,this._handleMove),y(document,this.options.endEvent,this._handleEnd),!((" "+t.target.className+" ").replace(w," ").indexOf(this.options.handleClass)>-1)){var e=this._getRelativePosition(t),i=this.range.getBoundingClientRect().left,n=this._getPositionFromNode(this.handle)-i;this._setPosition(e-this.grabX),e>=n&&et?e:t>i?i:t},E.prototype._setPosition=function(t){var e,i;e=this._getValueFromPosition(this._cap(t,0,this.maxHandleX)),i=this._getPositionFromValue(e),this.fill.style.width=i+this.grabX+"px",this.handle.style.left=i+"px",this._setValue(e),this.position=i,this.value=e,this._updatePercentFromValue(),(this.isInteractsNow||this.needTriggerEventss)&&(this.onSlideStart&&"function"==typeof this.onSlideStart&&0===this.onSlideEventsCount&&this.onSlideStart(this.value,this.percent,this.position),this.onSlide&&"function"==typeof this.onSlide&&this.onSlide(this.value,this.percent,this.position)),this.onSlideEventsCount++},E.prototype._setBufferPosition=function(t){var e,i,n,s=!0;if(isFinite(t))t=parseFloat(t);else{if(!r(t))return void console.warn("New position must be XXpx or XX%");t.indexOf("px")>0&&(s=!1),t=parseFloat(t)}return isNaN(t)?void console.warn("New position is NaN"):this.options.bufferClass?(e=s?t:t/this.rangeWidth*100,0>e&&(e=0),e>100&&(e=100),this.options.buffer=e,i=this.options.borderRadius/this.rangeWidth*100,n=e-i,0>n&&(n=0),this.buffer.style.width=n+"%",this.buffer.style.left=.5*i+"%",void(this.element.dataset.buffer=e)):void console.warn("You disabled buffer, it's className is empty")},E.prototype._getPositionFromNode=function(t){for(var e=0;null!==t;)e+=t.offsetLeft,t=t.offsetParent;return e},E.prototype._getRelativePosition=function(t){var e=this.range.getBoundingClientRect().left,i=0;return"undefined"!=typeof t.pageX?i=t.touches&&t.touches.length?t.touches[0].pageX:t.pageX:"undefined"!=typeof t.originalEvent.clientX?i=t.originalEvent.clientX:t.originalEvent.touches&&t.originalEvent.touches[0]&&"undefined"!=typeof t.originalEvent.touches[0].clientX?i=t.originalEvent.touches[0].clientX:t.currentPoint&&"undefined"!=typeof t.currentPoint.x&&(i=t.currentPoint.x),i-e},E.prototype._getPositionFromValue=function(t){var e,i;return e=(t-this.min)/(this.max-this.min),i=e*this.maxHandleX},E.prototype._getValueFromPosition=function(t){var e,i;return e=t/(this.maxHandleX||1),i=this.step*Math.round(e*(this.max-this.min)/this.step)+this.min,Number(i.toFixed(this.toFixed))},E.prototype._setValue=function(t,e){(t!==this.value||e)&&(this.element.value=t,this.value=t,m(this.element,"input",{origin:this.identifier}))},E.prototype.update=function(t,e){return e&&(this.needTriggerEvents=!0),l(t)&&(h(t.min)&&(this.element.setAttribute("min",""+t.min),this.min=t.min),h(t.max)&&(this.element.setAttribute("max",""+t.max),this.max=t.max),h(t.step)&&(this.element.setAttribute("step",""+t.step),this.step=t.step,this.toFixed=this._toFixed(t.step)),h(t.buffer)&&this._setBufferPosition(t.buffer),h(t.value)&&this._setValue(t.value)),this._update(),this.onSlideEventsCount=0,this.needTriggerEvents=!1,this},E.prototype.destroy=function(){b.call(this,document),window.removeEventListener("resize",this._handleResize,!1),this.element.removeEventListener("change",this._changeEventListener,!1),this.element.style.cssText="",delete this.element[C],this.range&&this.range.parentNode.removeChild(this.range)},E.create=function(t,e){function i(t){var i=t[C];i||(i=new E(t,e),t[C]=i)}t.length?Array.prototype.slice.call(t).forEach(function(t){i(t)}):i(t)},E}); \ No newline at end of file +!function(t){"use strict";"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?t():window.rangeSlider=t()}(function(){"use strict";function t(){var t=document.createElement("input");return t.setAttribute("type","range"),"text"!==t.type}function e(t,e){var i=Array.prototype.slice.call(arguments,2);return setTimeout(function(){return t.apply(null,i)},e)}function i(t,e){return e=e||100,function(){if(!t.debouncing){var i=Array.prototype.slice.apply(arguments);t.lastReturnVal=t.apply(window,i),t.debouncing=!0}return clearTimeout(t.debounceTimeout),t.debounceTimeout=setTimeout(function(){t.debouncing=!1},e),t.lastReturnVal}}function n(t){return!(0!==t.offsetWidth&&0!==t.offsetHeight&&t.open!==!1)}function s(t){for(var e=[],i=t.parentNode;n(i);)e.push(i),i=i.parentNode;return e}function o(t,e){function i(t){"undefined"!=typeof t.open&&(t.open=t.open?!1:!0)}var n=s(t),o=n.length,r=[],h=t[e];if(o){for(var a=0;o>a;a++)r[a]=n[a].style.display,n[a].style.display="block",n[a].style.height="0",n[a].style.overflow="hidden",n[a].style.visibility="hidden",i(n[a]);h=t[e];for(var l=0;o>l;l++)i(n[l]),n[l].style.display=r[l],n[l].style.height="",n[l].style.overflow="",n[l].style.visibility=""}return h}function r(t){return t===""+t}function h(t){return null!==t&&void 0!==t&&(r(t)&&isFinite(parseFloat(t))||isFinite(t))}function a(){if(!arguments.length)return null;for(var t=0,e=arguments.length;e>t;t++)if(h(arguments[t]))return arguments[t]}function l(t){return"[object Object]"===Object.prototype.toString.call(t)}function u(t,e){var i,n={};for(i in t)n[i]=t[i];for(i in e)n[i]=e[i];return n}function d(t,e){for(var i in e)t.style[i]=e[i];return t.style}function p(t,e){v(t,e)||(t.className+=" "+e)}function f(t,e){var i=" "+t.className.replace(/[\t\r\n]/g," ")+" ";if(v(t,e)){for(;i.indexOf(" "+e+" ")>=0;)i=i.replace(" "+e+" "," ");t.className=i.replace(/^\s+|\s+$/g,"")}}function c(t,e,i){for(i&&e(t);t.parentNode&&!e(t);)t=t.parentNode;return t}function m(t,e,i){if(!r(e))throw new TypeError("event name must be String");if(!(t instanceof HTMLElement))throw new TypeError("element must be HTMLElement");e=e.trim();var n=new CustomEvent(e,i);t.dispatchEvent(n)}function v(t,e){return new RegExp(" "+e+" ").test(" "+t.className+" ")}function g(t,e){t.parentNode.insertBefore(e,t.nextSibling)}function y(t,e,i){e.forEach(function(e){t[x]||(t[x]={}),t[x][e]||(t[x][e]=[]),t.addEventListener(e,i,!1),t[x][e].indexOf(i)<0&&t[x][e].push(i)})}function _(t,e,i){e.forEach(function(e){t.removeEventListener(e,i,!1);var n;t[x]&&t[x][e]&&(n=t[x][e].indexOf(i))>-1&&t[x][e].splice(n,1)})}function b(t){function e(t){t===i._startEventListener&&this.el.removeEventListener(this.eventName,t,!1)}if(t[x]){var i=this;for(var n in t[x])t[x][n].forEach(e,{eventName:n,el:t});t[x]={}}}function E(t,e){var i,n,s;return this.element=t,this.options=u(X,e),this.polyfill=this.options.polyfill,this.onInit=this.options.onInit,this.onSlide=this.options.onSlide,this.onSlideStart=this.options.onSlideStart,this.onSlideEnd=this.options.onSlideEnd,this.onSlideEventsCount=-1,this.isInteractsNow=!1,this.needTriggerEvents=!1,!this.polyfill&&L?!1:(this.options.buffer=this.options.buffer||parseFloat(this.element.dataset.buffer),this.identifier="js-"+C+"-"+P++,this.min=a(this.options.min,parseFloat(this.element.getAttribute("min")),i=0),this.max=a(this.options.max,parseFloat(this.element.getAttribute("max")),n=S),this.value=a(this.options.value,this.element.value,parseFloat(this.element.value||this.min+(this.max-this.min)/2)),this.step=a(this.options.step,parseFloat(this.element.getAttribute("step"))||(s=1)),this.percent=null,this._updatePercentFromValue(),this.toFixed=this._toFixed(this.step),this.fill=document.createElement("div"),this.fill.className=this.options.fillClass,this.handle=document.createElement("div"),this.handle.className=this.options.handleClass,this.range=document.createElement("div"),this.range.className=this.options.rangeClass,this.range.id=this.identifier,this.range.appendChild(this.handle),this.range.appendChild(this.fill),this.options.bufferClass&&(this.buffer=document.createElement("div"),this.buffer.className=this.options.bufferClass,this.range.appendChild(this.buffer)),h(this.options.value)&&(this._setValue(this.options.value,!0),this.element.value=this.options.value),h(this.options.buffer)&&(this.element.dataset.buffer=this.options.buffer),(h(this.options.min)||i)&&this.element.setAttribute("min",""+this.min),(h(this.options.max)||n)&&this.element.setAttribute("max",""+this.max),(h(this.options.step)||s)&&this.element.setAttribute("step",""+this.step),g(this.element,this.range),d(this.element,{position:"absolute",width:"1px",height:"1px",overflow:"hidden",opacity:"0"}),this._handleDown=this._handleDown.bind(this),this._handleMove=this._handleMove.bind(this),this._handleEnd=this._handleEnd.bind(this),this._startEventListener=this._startEventListener.bind(this),this._changeEventListener=this._changeEventListener.bind(this),this._handleResize=this._handleResize.bind(this),this._init(),window.addEventListener("resize",this._handleResize,!1),y(document,this.options.startEvent,this._startEventListener),void this.element.addEventListener("change",this._changeEventListener,!1))}var x="eventListenerList",w=new RegExp("/[\\n\\t]/","g"),S=100,N=300,F=50,C="rangeSlider",P=0,L=t(),X={polyfill:!0,rangeClass:"rangeSlider",disabledClass:"rangeSlider--disabled",fillClass:"rangeSlider__fill",bufferClass:"rangeSlider__buffer",handleClass:"rangeSlider__handle",startEvent:["mousedown","touchstart","pointerdown"],moveEvent:["mousemove","touchmove","pointermove"],endEvent:["mouseup","touchend","pointerup"],min:null,max:null,step:null,value:null,buffer:null,borderRadius:10};return E.prototype.constructor=E,E.prototype._toFixed=function(t){return(t+"").replace(".","").length-1},E.prototype._init=function(){this.onInit&&"function"==typeof this.onInit&&this.onInit(),this._update()},E.prototype._updatePercentFromValue=function(){this.percent=(this.value-this.min)/(this.max-this.min)},E.prototype._startEventListener=function(t,e){var i=this,n=t.target,s=!1;c(n,function(t){return s=t.id===i.identifier&&!v(t,i.options.disabledClass)},!0),s&&this._handleDown(t,e)},E.prototype._changeEventListener=function(t,e){if(!e||e.origin!==this.identifier){var i=t.target.value,n=this._getPositionFromValue(i);this._setPosition(n)}},E.prototype._update=function(){this.handleWidth=o(this.handle,"offsetWidth"),this.rangeWidth=o(this.range,"offsetWidth"),this.maxHandleX=this.rangeWidth-this.handleWidth,this.grabX=this.handleWidth/2,this.position=this._getPositionFromValue(this.value),this.element.disabled?p(this.range,this.options.disabledClass):f(this.range,this.options.disabledClass),this._setPosition(this.position),this.options.bufferClass&&this.options.buffer&&this._setBufferPosition(this.options.buffer),this._updatePercentFromValue(),this.element.dispatchEvent(new Event("change"))},E.prototype._handleResize=function(){var t=this;return i(function(){e(function(){t._update()},N)},F)()},E.prototype._handleDown=function(t){if(this.isInteractsNow=!0,t.preventDefault(),y(document,this.options.moveEvent,this._handleMove),y(document,this.options.endEvent,this._handleEnd),!((" "+t.target.className+" ").replace(w," ").indexOf(this.options.handleClass)>-1)){var e=this._getRelativePosition(t),i=this.range.getBoundingClientRect().left,n=this._getPositionFromNode(this.handle)-i;this._setPosition(e-this.grabX),e>=n&&et?e:t>i?i:t},E.prototype._setPosition=function(t){var e,i;e=this._getValueFromPosition(this._cap(t,0,this.maxHandleX)),i=this._getPositionFromValue(e),this.fill.style.width=i+this.grabX+"px",this.handle.style.left=i+"px",this._setValue(e),this.position=i,this.value=e,this._updatePercentFromValue(),(this.isInteractsNow||this.needTriggerEventss)&&(this.onSlideStart&&"function"==typeof this.onSlideStart&&0===this.onSlideEventsCount&&this.onSlideStart(this.value,this.percent,this.position),this.onSlide&&"function"==typeof this.onSlide&&this.onSlide(this.value,this.percent,this.position)),this.onSlideEventsCount++},E.prototype._setBufferPosition=function(t){var e,i,n,s=!0;if(isFinite(t))t=parseFloat(t);else{if(!r(t))return void console.warn("New position must be XXpx or XX%");t.indexOf("px")>0&&(s=!1),t=parseFloat(t)}return isNaN(t)?void console.warn("New position is NaN"):this.options.bufferClass?(e=s?t:t/this.rangeWidth*100,0>e&&(e=0),e>100&&(e=100),this.options.buffer=e,i=this.options.borderRadius/this.rangeWidth*100,n=e-i,0>n&&(n=0),this.buffer.style.width=n+"%",this.buffer.style.left=.5*i+"%",void(this.element.dataset.buffer=e)):void console.warn("You disabled buffer, it's className is empty")},E.prototype._getPositionFromNode=function(t){for(var e=0;null!==t;)e+=t.offsetLeft,t=t.offsetParent;return e},E.prototype._getRelativePosition=function(t){var e=this.range.getBoundingClientRect().left,i=0;return"undefined"!=typeof t.pageX?i=t.touches&&t.touches.length?t.touches[0].pageX:t.pageX:"undefined"!=typeof t.originalEvent.clientX?i=t.originalEvent.clientX:t.originalEvent.touches&&t.originalEvent.touches[0]&&"undefined"!=typeof t.originalEvent.touches[0].clientX?i=t.originalEvent.touches[0].clientX:t.currentPoint&&"undefined"!=typeof t.currentPoint.x&&(i=t.currentPoint.x),i-e},E.prototype._getPositionFromValue=function(t){var e,i;return e=(t-this.min)/(this.max-this.min),i=e*this.maxHandleX},E.prototype._getValueFromPosition=function(t){var e,i;return e=t/(this.maxHandleX||1),i=this.step*Math.round(e*(this.max-this.min)/this.step)+this.min,Number(i.toFixed(this.toFixed))},E.prototype._setValue=function(t,e){(t!==this.value||e)&&(this.element.value=t,this.value=t,m(this.element,"input",{origin:this.identifier}))},E.prototype.update=function(t,e){return e&&(this.needTriggerEvents=!0),l(t)&&(h(t.min)&&(this.element.setAttribute("min",""+t.min),this.min=t.min),h(t.max)&&(this.element.setAttribute("max",""+t.max),this.max=t.max),h(t.step)&&(this.element.setAttribute("step",""+t.step),this.step=t.step,this.toFixed=this._toFixed(t.step)),h(t.buffer)&&this._setBufferPosition(t.buffer),h(t.value)&&this._setValue(t.value)),this._update(),this.onSlideEventsCount=0,this.needTriggerEvents=!1,this},E.prototype.destroy=function(){b.call(this,document),window.removeEventListener("resize",this._handleResize,!1),this.element.removeEventListener("change",this._changeEventListener,!1),this.element.style.cssText="",delete this.element[C],this.range&&this.range.parentNode.removeChild(this.range)},E.create=function(t,e){function i(t){var i=t[C];i||(i=new E(t,e),t[C]=i)}t.length?Array.prototype.slice.call(t).forEach(function(t){i(t)}):i(t)},E}); \ No newline at end of file diff --git a/package.json b/package.json index 4f08eec..da1bbf8 100644 --- a/package.json +++ b/package.json @@ -36,13 +36,13 @@ }, "dependencies": {}, "devDependencies": { - "del": "^1.1.1", - "gulp": "^3.8.10", - "gulp-jshint": "^1.9.2", - "gulp-minify-css": "^0.4.5", - "gulp-rename": "^1.2.0", - "gulp-uglify": "^1.1.0", - "gulp-watch": "^3.0.0" + "del": "^1.2.0", + "gulp": "^3.9.0", + "gulp-jshint": "^1.11.0", + "gulp-minify-css": "^1.1.6", + "gulp-rename": "^1.2.2", + "gulp-uglify": "^1.2.0", + "gulp-watch": "^4.2.4" }, "scripts": { "test": "gulp jshint" diff --git a/src/rangeSlider.js b/src/rangeSlider.js index 5a167cc..21c1d6b 100644 --- a/src/rangeSlider.js +++ b/src/rangeSlider.js @@ -270,7 +270,7 @@ if (!isString(name)) { throw new TypeError('event name must be String'); } - if (!el instanceof HTMLElement) { + if (!(el instanceof HTMLElement)) { throw new TypeError('element must be HTMLElement'); } name = name.trim(); @@ -361,7 +361,7 @@ * @this {Object} event name */ function rm(listener) { - if(listener === instance._startEventListener){ + if (listener === instance._startEventListener) { this.el.removeEventListener(this.eventName, listener, false); } } @@ -603,7 +603,7 @@ // Ok we're done fire the change event triggerEvent(this.element, 'change', {origin: this.identifier}); - if(this.isInteractsNow || this.needTriggerEvents){ + if (this.isInteractsNow || this.needTriggerEvents) { if (this.onSlideEnd && typeof this.onSlideEnd === 'function') { this.onSlideEnd(this.value, this.percent, this.position); } @@ -639,7 +639,7 @@ this.value = value; this._updatePercentFromValue(); - if(this.isInteractsNow || this.needTriggerEventss){ + if (this.isInteractsNow || this.needTriggerEventss) { if (this.onSlideStart && typeof this.onSlideStart === 'function' && this.onSlideEventsCount === 0) { this.onSlideStart(this.value, this.percent, this.position); } @@ -766,7 +766,7 @@ * @returns {Plugin} */ Plugin.prototype.update = function (obj, triggerEvents) { - if(triggerEvents){ + if (triggerEvents) { this.needTriggerEvents = true; } if (isObject(obj)) {