"use strict";var utils=this.utils||{};utils.seekbars=function(){function getProgressValue(value,min,max){var out=value;return out=value>=max?MAX_VALUE:min>=value?MIN_VALUE:(value-min)/(max-min)}function getSliderValue(value,min,max){var out=value;return out=value>=MAX_VALUE?max:MIN_VALUE>=value?min:(max-min)*value+min}function initialize(){reset();for(var sliderElements=document.querySelectorAll('[role="slider"]'),i=0;i<sliderElements.length;i++)sliders.push(new Slider(sliderElements[i]))}function reset(){sliders.forEach(function(slider){slider.destroy()}),sliders=[]}function reArrange(){sliders.forEach(function(slider){slider.calculateDimensions(),slider.valuestart=slider.progress.value,slider.placeHandler(slider.valuestart)})}var vendor=/webkit/i.test(navigator.appVersion)?"webkit":/firefox/i.test(navigator.userAgent)?"Moz":"opera"in window?"O":"",transformProp=vendor+"Transform",MIN_VALUE=0,MAX_VALUE=1,sliders=[],isTouch="ontouchstart"in window,touchstart=isTouch?"touchstart":"mousedown",touchmove=isTouch?"touchmove":"mousemove",touchend=isTouch?"touchend":"mouseup",getX=function(){return isTouch?function(e){return e.touches[0].pageX}:function(e){return e.pageX}}(),Slider=function(slider){this.slider=slider;var progress=(this.handler=slider.querySelector("progress + button"),this.progress=slider.querySelector("progress"));this.calculateDimensions();var vmin=this.valuemin=parseFloat(slider.getAttribute("aria-valuemin"))||MIN_VALUE,vmax=this.valuemax=parseFloat(slider.getAttribute("aria-valuemax"))||MAX_VALUE;vmin>vmax&&(vmax=MAX_VALUE);var vnow=parseFloat(slider.getAttribute("aria-valuenow"));vnow||0===vnow||(vnow=vmin,slider.setAttribute("aria-valuenow",vnow));var value=this.valuestart=getProgressValue(vnow,vmin,vmax);this.placeHandler(value),progress.value=value,progress.max=MAX_VALUE,slider.addEventListener(touchstart,this)};Slider.prototype={handleEvent:function(evt){switch(evt.type){case touchstart:this.slider.removeEventListener(touchstart,this),this.currentX=getX(evt),this.startX=this.handler.getBoundingClientRect().left+this.halfHandlerWidth,this.progressLeft>this.currentX&&(this.currentX=this.progressLeft),this.progressRight<this.currentX&&(this.currentX=this.progressRight),this.updateUI(),evt.target===this.handler&&window.addEventListener(touchmove,this),window.addEventListener(touchend,this);break;case touchmove:evt.preventDefault();var x=getX(evt);x<this.progressLeft?this.setValue(MIN_VALUE):x>this.progressRight?this.setValue(MAX_VALUE):(this.currentX=x,this.updateUI());break;case touchend:evt.preventDefault(),this.deltaX=this.getDeltaX(),this.slider.addEventListener(touchstart,this),window.removeEventListener(touchmove,this),window.removeEventListener(touchend,this)}},getDeltaX:function(){return this.deltaX+this.currentX-this.startX},updateUI:function(){var deltaX=this.getDeltaX();this.handler.style[transformProp]="translateX("+deltaX+"px)",this.setValue(this.valuestart+deltaX/this.progressWidth)},setValue:function(value){this.progress.value=value,this.slider.setAttribute("aria-valuenow",getSliderValue(value,this.valuemin,this.valuemax)),this.slider.dispatchEvent(new Event("change",{bubbles:!0}))},calculateDimensions:function(){this.progressWidth=this.progress.clientWidth,this.halfHandlerWidth=this.handler.clientWidth/2,this.progressLeft=this.progress.getBoundingClientRect().left,this.progressRight=this.progressLeft+this.progressWidth,this.deltaX=0},placeHandler:function(value){this.handler.style.left=this.progressWidth*value+this.progressLeft-this.progress.parentNode.getBoundingClientRect().left+"px",this.handler.style[transformProp]="translateX(0)"},destroy:function(){this.slider.removeEventListener(touchstart,this),this.progress=this.slider=this.handler=this.valuemax=this.valuemin=this.valuestart=this.progressWidth=this.deltaX=this.currentX=this.progressLeft=this.progressRight=null}},window.addEventListener("resize",reArrange);try{screen.addEventListener("orientationchange",reArrange)}catch(ex){window.addEventListener("orientationchange",reArrange)}return"complete"===document.readyState?initialize():document.addEventListener("DOMContentLoaded",function loaded(){document.removeEventListener("DOMContentLoaded",loaded),initialize()}),{init:initialize,destroy:reset,bind:function(elem){elem="object"==typeof elem?elem:document.querySelector(elem),sliders.push(new Slider(elem))},create:function(options){var slider=document.createElement("div");slider.setAttribute("role","slider"),options&&Object.keys(options).forEach(function(key){slider.setAttribute(key,options[key])});var wrapper=document.createElement("div"),progress=document.createElement("progress");return progress.setAttribute("role","presentation"),wrapper.appendChild(progress),wrapper.appendChild(document.createElement("button")),slider.appendChild(wrapper),slider}}}();