aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/plyr.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2019-04-12 12:19:48 +1000
committerSam Potts <sam@potts.es>2019-04-12 12:19:48 +1000
commitb247093495c3402dbe7c14e3faeff8475f4e277c (patch)
tree8db601f188caf539277f9760ca93d02e9deb442b /src/js/plyr.js
parent9ca7b861a925ec0412006f7cc926bfa1859a0daa (diff)
downloadplyr-b247093495c3402dbe7c14e3faeff8475f4e277c.tar.lz
plyr-b247093495c3402dbe7c14e3faeff8475f4e277c.tar.xz
plyr-b247093495c3402dbe7c14e3faeff8475f4e277c.zip
Aspect ratio improvements (fixes #1042, fixes #1366)
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r--src/js/plyr.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js
index c06df984..1dd3ecb9 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -26,6 +26,7 @@ import { off, on, once, triggerEvent, unbindListeners } from './utils/events';
import is from './utils/is';
import loadSprite from './utils/loadSprite';
import { cloneDeep, extend } from './utils/objects';
+import { getAspectRatio, reduceAspectRatio, setAspectRatio, validateRatio } from './utils/style';
import { parseUrl } from './utils/urls';
// Private properties
@@ -847,6 +848,34 @@ class Plyr {
}
/**
+ * Get the current aspect ratio in use
+ */
+ get ratio() {
+ const ratio = reduceAspectRatio(getAspectRatio.call(this));
+
+ return is.array(ratio) ? ratio.join(':') : ratio;
+ }
+
+ /**
+ * Set video aspect ratio
+ */
+ set ratio(input) {
+ if (!this.isVideo) {
+ this.debug.warn('Aspect ratio can only be set for video');
+ return;
+ }
+
+ if (!is.string(input) || !validateRatio(input)) {
+ this.debug.error(`Invalid aspect ratio specified (${input})`);
+ return;
+ }
+
+ this.config.ratio = input;
+
+ setAspectRatio.call(this);
+ }
+
+ /**
* Set the autoplay state
* @param {Boolean} input - Whether to autoplay or not
*/