diff options
author | Sam Potts <sam@potts.es> | 2019-01-29 21:34:40 +1100 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2019-01-29 21:34:40 +1100 |
commit | b1da599b5d5891dc1dca44bd6aa9d8d03872fdcb (patch) | |
tree | c799fb2b444482f6d99dcdf3f16a957b290888c0 /src/js/utils/style.js | |
parent | afc969bac322f9b17dc0554a65fa848eb998c8e6 (diff) | |
parent | b798368ba68853558819d79a995aa0deec27f95e (diff) | |
download | plyr-b1da599b5d5891dc1dca44bd6aa9d8d03872fdcb.tar.lz plyr-b1da599b5d5891dc1dca44bd6aa9d8d03872fdcb.tar.xz plyr-b1da599b5d5891dc1dca44bd6aa9d8d03872fdcb.zip |
Merge branch 'develop' into beta
Diffstat (limited to 'src/js/utils/style.js')
-rw-r--r-- | src/js/utils/style.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/js/utils/style.js b/src/js/utils/style.js new file mode 100644 index 00000000..a8eb393b --- /dev/null +++ b/src/js/utils/style.js @@ -0,0 +1,40 @@ +// ========================================================================== +// Style utils +// ========================================================================== + +import is from './is'; + +/* function reduceAspectRatio(width, height) { + const getRatio = (w, h) => (h === 0 ? w : getRatio(h, w % h)); + const ratio = getRatio(width, height); + return `${width / ratio}:${height / ratio}`; +} */ + +// Set aspect ratio for responsive container +export function setAspectRatio(input) { + let ratio = input; + + if (!is.string(ratio) && !is.nullOrUndefined(this.embed)) { + ({ ratio } = this.embed); + } + + if (!is.string(ratio)) { + ({ ratio } = this.config); + } + + const [x, y] = ratio.split(':').map(Number); + const padding = (100 / x) * y; + + this.elements.wrapper.style.paddingBottom = `${padding}%`; + + // For Vimeo we have an extra <div> to hide the standard controls and UI + if (this.isVimeo && this.supported.ui) { + const height = 240; + const offset = (height - padding) / (height / 50); + this.media.style.transform = `translateY(-${offset}%)`; + } + + return { padding, ratio }; +} + +export default { setAspectRatio }; |