diff options
author | Sam Potts <sam@selz.com> | 2018-01-22 23:15:52 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-22 23:15:52 +1100 |
commit | 3aa5747c9018b99fe7bc1d8ad4d67cea62ae5489 (patch) | |
tree | 4278b90afa91cb8237b9faa5e50909c4ea832fc6 /src/js/utils.js | |
parent | 6831c3053470d092c11536a837ebf8c1a8b5c530 (diff) | |
parent | 5671235fd93eac4554d2c522461df813b589a7f4 (diff) | |
download | plyr-3aa5747c9018b99fe7bc1d8ad4d67cea62ae5489.tar.lz plyr-3aa5747c9018b99fe7bc1d8ad4d67cea62ae5489.tar.xz plyr-3aa5747c9018b99fe7bc1d8ad4d67cea62ae5489.zip |
Merge pull request #760 from sampotts/beta-with-ads
Beta with ads
Diffstat (limited to 'src/js/utils.js')
-rw-r--r-- | src/js/utils.js | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/js/utils.js b/src/js/utils.js index 81da8821..f82df2a4 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -50,6 +50,9 @@ const utils = { track(input) { return this.instanceof(input, TextTrack) || (!this.nullOrUndefined(input) && this.string(input.kind)); }, + url(input) { + return !this.nullOrUndefined(input) && /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(input); + }, nullOrUndefined(input) { return input === null || typeof input === 'undefined'; }, @@ -602,6 +605,32 @@ const utils = { return (current / max * 100).toFixed(2); }, + // Time helpers + getHours(value) { return parseInt((value / 60 / 60) % 60, 10); }, + getMinutes(value) { return parseInt((value / 60) % 60, 10); }, + getSeconds(value) { return parseInt(value % 60, 10); }, + + // Format time to UI friendly string + formatTime(time = 0, displayHours = false, inverted = false) { + // Format time component to add leading zero + const format = value => `0${value}`.slice(-2); + + // Breakdown to hours, mins, secs + let hours = this.getHours(time); + const mins = this.getMinutes(time); + const secs = this.getSeconds(time); + + // Do we need to display hours? + if (displayHours || hours > 0) { + hours = `${hours}:`; + } else { + hours = ''; + } + + // Render + return `${inverted ? '-' : ''}${hours}${format(mins)}:${format(secs)}`; + }, + // Deep extend destination object with N more objects extend(target = {}, ...sources) { if (!sources.length) { @@ -746,9 +775,9 @@ const utils = { // Force repaint of element repaint(element) { window.setTimeout(() => { - element.setAttribute('hidden', ''); + utils.toggleHidden(element, true); element.offsetHeight; // eslint-disable-line - element.removeAttribute('hidden'); + utils.toggleHidden(element, false); }, 0); }, }; |