aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2019-01-14 00:33:48 +1100
committerSam Potts <sam@potts.es>2019-01-14 00:33:48 +1100
commit6782737009bec028b393dbfb8c9897cd0c6df48f (patch)
treeb60c7a6bce9d78e9b8b3244c254fc4e234b0165c /src/js/utils
parent6be125db8762c7ee8d29282ff5bcd08e6bcee042 (diff)
downloadplyr-6782737009bec028b393dbfb8c9897cd0c6df48f.tar.lz
plyr-6782737009bec028b393dbfb8c9897cd0c6df48f.tar.xz
plyr-6782737009bec028b393dbfb8c9897cd0c6df48f.zip
Fullscreen fixes
Diffstat (limited to 'src/js/utils')
-rw-r--r--src/js/utils/browser.js1
-rw-r--r--src/js/utils/style.js40
2 files changed, 41 insertions, 0 deletions
diff --git a/src/js/utils/browser.js b/src/js/utils/browser.js
index d574f683..11705074 100644
--- a/src/js/utils/browser.js
+++ b/src/js/utils/browser.js
@@ -5,6 +5,7 @@
const browser = {
isIE: /* @cc_on!@ */ false || !!document.documentMode,
+ isEdge: window.navigator.userAgent.includes('Edge'),
isWebkit: 'WebkitAppearance' in document.documentElement.style && !/Edge/.test(navigator.userAgent),
isIPhone: /(iPhone|iPod)/gi.test(navigator.platform),
isIos: /(iPad|iPhone|iPod)/gi.test(navigator.platform),
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 };