From 408ecf60d271506f617eb62f93cd668b5aaf2aaa Mon Sep 17 00:00:00 2001 From: ejb Date: Tue, 22 Nov 2016 21:05:10 -0500 Subject: [PATCH] Add hours option --- Readme.md | 4 ++++ package.json | 2 +- progressor.js | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index be7026a..cddfcf7 100644 --- a/Readme.md +++ b/Readme.md @@ -73,6 +73,10 @@ A lightweight JavaScript library that creates customisable progress bars for HTM ## Changelog +### v1.1.0 + +- Add `hours` option + ### v1.0.1 - Bugfix: work as a global diff --git a/package.json b/package.json index c5f9799..fba9b64 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "progressor.js", "description": "Lightweight, customisable progress bars for HTML5 video & audio", - "version": "1.0.1", + "version": "1.1.0", "homepage": "https://github.com/ejb/progressor.js", "author": "Elliot Bentley (http://ejb.github.io)", "keywords": [ diff --git a/progressor.js b/progressor.js index 2f32df5..779b0ec 100644 --- a/progressor.js +++ b/progressor.js @@ -8,6 +8,7 @@ this._bar = options.bar; this._text = options.text; this._time = options.time; + this._hours = options.hours; this.initProgressBar(); this.initMedia(); }; @@ -52,9 +53,19 @@ }; Progressor.prototype.formatTime = function ( time ) { - var minutes = Math.floor(time / 60); - var seconds = ("0" + Math.round( time - minutes * 60 ) ).slice(-2); - return minutes+":"+seconds; + var hours = Math.floor(time / 3600).toString(); + if (this._hours) { + var minutes = ("0" + Math.floor(time / 60) % 60).slice(-2); + var seconds = ("0" + Math.floor( time % 60 )).slice(-2); + if (hours !== '0') { + return hours + ":" + minutes + ":" + seconds; + } + return minutes + ":" + seconds; + } else { + var minutes = Math.floor(time / 60); + var seconds = ("0" + Math.round( time - minutes * 60 ) ).slice(-2); + return minutes+":"+seconds; + } } Progressor.prototype.updateTimeCount = function(){