diff --git a/Readme.md b/Readme.md index a599b13..ebf1eb2 100644 --- a/Readme.md +++ b/Readme.md @@ -73,6 +73,10 @@ A lightweight JavaScript library that creates customisable progress bars for HTM ## Changelog +### v0.2.2 + +- Fixed class name bug + ### v0.2.1 - Fixed loss-of-focus bug diff --git a/progressor.js b/progressor.js index c52e96b..63875e2 100644 --- a/progressor.js +++ b/progressor.js @@ -20,7 +20,7 @@ Progressor.prototype.initProgressBar = function(){ this._textBox.textContent = this._text || ""; this._bar.style.position = "relative"; this._bar.style.zIndex = 1; - this._bar.className = this._bar.className + "progressor"; + this._bar.className = this._bar.className + " progressor"; this._progress = document.createElement('div'); this._progress.className = "progressor-progress"; diff --git a/progressor.min.js b/progressor.min.js index d4dc51e..6a30e5e 100644 --- a/progressor.min.js +++ b/progressor.min.js @@ -1 +1 @@ -function Progressor(a){this._media=a.media,this._bar=a.bar,this._text=a.text,this._time=a.time,this.initProgressBar(),this.initMedia()}Progressor.prototype.initMedia=function(){this._media.addEventListener("timeupdate",this.updateProgress.bind(this),!1),this._media.addEventListener("timeupdate",this.updateTimeCount.bind(this),!1),this.addClickEvents(),this.updateTimeCount(this._media)},Progressor.prototype.initProgressBar=function(){this._textBox=document.createElement("span"),this._textBox.textContent=this._text||"",this._bar.style.position="relative",this._bar.style.zIndex=1,this._bar.className=this._bar.className+"progressor",this._progress=document.createElement("div"),this._progress.className="progressor-progress",this._progress.style.width="0%",this._progress.style.height="100%",this._progress.style.position="absolute",this._progress.style.top=0,this._progress.style.zIndex=-1,this._bar.style.webkitUserSelect="none",this._bar.style.userSelect="none",this._bar.appendChild(this._textBox),this._bar.appendChild(this._progress)},Progressor.prototype.updateProgress=function(){this.updateTimeCount();var a=0;this._media.currentTime>0&&(a=Math.floor(100/this._media.duration*this._media.currentTime)),this._bar.getElementsByTagName("div")[0].style.width=a+"%"},Progressor.prototype.formatTime=function(a){var b=Math.floor(a/60),c=("0"+Math.round(a-60*b)).slice(-2);return b+":"+c},Progressor.prototype.updateTimeCount=function(){if(this._time){var a=this.formatTime(this._media.currentTime),b=this.formatTime(this._media.duration);isNaN(this._media.duration)===!0&&(b="00:00"),this._time.innerHTML=a+"/"+b}},Progressor.prototype.timeFromCursorPosition=function(a,b,c){var d=a.getBoundingClientRect(),e=b.clientX-d.left,f=e/d.width;return f*c},Progressor.prototype.setMediaProgress=function(a){this._media.currentTime=this.timeFromCursorPosition(this._bar,a,this._media.duration),this.updateProgress()},Progressor.prototype.remove=function(){function a(a){var b=a.cloneNode(!0);a.parentNode.replaceChild(b,a)}this._time.innerHTML="",this._bar.removeChild(this._textBox),this._bar.removeChild(this._progress),this._bar.style.position="",this._bar.style.zIndex="",this._bar.style.webkitUserSelect="",this._bar.style.userSelect="",this._bar.classList.remove("progressor"),a(this._bar),a(this._media)},Progressor.prototype.addClickEvents=function(){var a=!1,b=!1,c="",d=function(c){a=!0,b=!this._media.paused,this._media.pause(),this.setMediaProgress(c)},e=function(){clearInterval(c),a=!1,1==b&&(this._media.play(),b=!1)},f=function(b){a===!0&&(c=setInterval(this.setMediaProgress(b),1e3))};this._bar.addEventListener("mousedown",d.bind(this)),document.addEventListener("mouseup",e.bind(this)),document.addEventListener("mousemove",f.bind(this))};var progressor={init:function(){console.error("'progressor.init()' is deprecated. Please use 'Progressor()'.")}}; \ No newline at end of file +function Progressor(a){this._media=a.media,this._bar=a.bar,this._text=a.text,this._time=a.time,this.initProgressBar(),this.initMedia()}Progressor.prototype.initMedia=function(){this._media.addEventListener("timeupdate",this.updateProgress.bind(this),!1),this._media.addEventListener("timeupdate",this.updateTimeCount.bind(this),!1),this.addClickEvents(),this.updateTimeCount(this._media)},Progressor.prototype.initProgressBar=function(){this._textBox=document.createElement("span"),this._textBox.textContent=this._text||"",this._bar.style.position="relative",this._bar.style.zIndex=1,this._bar.className=this._bar.className+" progressor",this._progress=document.createElement("div"),this._progress.className="progressor-progress",this._progress.style.width="0%",this._progress.style.height="100%",this._progress.style.position="absolute",this._progress.style.top=0,this._progress.style.zIndex=-1,this._bar.style.webkitUserSelect="none",this._bar.style.userSelect="none",this._bar.appendChild(this._textBox),this._bar.appendChild(this._progress)},Progressor.prototype.updateProgress=function(){this.updateTimeCount();var a=0;this._media.currentTime>0&&(a=Math.floor(100/this._media.duration*this._media.currentTime)),this._bar.getElementsByTagName("div")[0].style.width=a+"%"},Progressor.prototype.formatTime=function(a){var b=Math.floor(a/60),c=("0"+Math.round(a-60*b)).slice(-2);return b+":"+c},Progressor.prototype.updateTimeCount=function(){if(this._time){var a=this.formatTime(this._media.currentTime),b=this.formatTime(this._media.duration);isNaN(this._media.duration)===!0&&(b="00:00"),this._time.innerHTML=a+"/"+b}},Progressor.prototype.timeFromCursorPosition=function(a,b,c){var d=a.getBoundingClientRect(),e=b.clientX-d.left,f=e/d.width;return f*c},Progressor.prototype.setMediaProgress=function(a){this._media.currentTime=this.timeFromCursorPosition(this._bar,a,this._media.duration),this.updateProgress()},Progressor.prototype.remove=function(){function a(a){var b=a.cloneNode(!0);a.parentNode.replaceChild(b,a)}this._time.innerHTML="",this._bar.removeChild(this._textBox),this._bar.removeChild(this._progress),this._bar.style.position="",this._bar.style.zIndex="",this._bar.style.webkitUserSelect="",this._bar.style.userSelect="",this._bar.classList.remove("progressor"),a(this._bar),a(this._media)},Progressor.prototype.addClickEvents=function(){var a=!1,b=!1,c="",d=function(c){a=!0,b=!this._media.paused,this._media.pause(),this.setMediaProgress(c)},e=function(){clearInterval(c),a=!1,1==b&&(this._media.play(),b=!1)},f=function(b){a===!0&&(c=setInterval(this.setMediaProgress(b),1e3))};this._bar.addEventListener("mousedown",d.bind(this)),document.addEventListener("mouseup",e.bind(this)),document.addEventListener("mousemove",f.bind(this))};var progressor={init:function(){console.error("'progressor.init()' is deprecated. Please use 'Progressor()'.")}}; \ No newline at end of file