Migrate custom properties from media to parent

This commit is contained in:
Sam Potts 2020-04-23 22:06:36 +10:00
parent 145f2ae24f
commit a9c4e77d1b
2 changed files with 23 additions and 0 deletions

View File

@ -269,6 +269,9 @@ class Plyr {
wrap(this.media, this.elements.container); wrap(this.media, this.elements.container);
} }
// Migrate custom properties from media to container (so they work 😉)
ui.migrateStyles.call(this);
// Add style hook // Add style hook
ui.addStyleHook.call(this); ui.addStyleHook.call(this);

View File

@ -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; export default ui;