aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2020-04-23 22:06:36 +1000
committerSam Potts <sam@potts.es>2020-04-23 22:06:36 +1000
commita9c4e77d1bcf1dedce9a3030017ddef2d3a924c8 (patch)
tree724e351d38c07c95b1637f5e4d2720946f4b4b8f /src
parent145f2ae24fc2177cd4b778ccdb9f7a6c46c3ba60 (diff)
downloadplyr-a9c4e77d1bcf1dedce9a3030017ddef2d3a924c8.tar.lz
plyr-a9c4e77d1bcf1dedce9a3030017ddef2d3a924c8.tar.xz
plyr-a9c4e77d1bcf1dedce9a3030017ddef2d3a924c8.zip
Migrate custom properties from media to parent
Diffstat (limited to 'src')
-rw-r--r--src/js/plyr.js3
-rw-r--r--src/js/ui.js20
2 files changed, 23 insertions, 0 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js
index 9b18bc35..14050929 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -269,6 +269,9 @@ class Plyr {
wrap(this.media, this.elements.container);
}
+ // Migrate custom properties from media to container (so they work 😉)
+ ui.migrateStyles.call(this);
+
// Add style hook
ui.addStyleHook.call(this);
diff --git a/src/js/ui.js b/src/js/ui.js
index c7553c72..c9ad7d90 100644
--- a/src/js/ui.js
+++ b/src/js/ui.js
@@ -264,6 +264,26 @@ const ui = {
);
}
},
+
+ // Migrate any custom properties from the media to the parent
+ migrateStyles() {
+ // Loop through values (as they are the keys when the object is spread 🤔)
+ Object.values({ ...this.media.style })
+ // We're only fussed about Plyr specific properties
+ .filter(key => key.startsWith('--plyr'))
+ .forEach(key => {
+ // Set on the container
+ this.elements.container.style.setProperty(key, this.media.style.getPropertyValue(key));
+
+ // Clean up from media element
+ this.media.style.removeProperty(key);
+ });
+
+ // Remove attribute if empty
+ if (is.empty(this.media.style)) {
+ this.media.removeAttribute('style');
+ }
+ },
};
export default ui;