Skip to content

Commit

Permalink
use mediaElementAttributes in createMediaView
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiiRochi committed Jun 24, 2022
1 parent 330546c commit 82df148
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/js/view/createMediaView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@ export const createMediaView = _ =>
ignoreRect: true,
create: ({ root, props }) => {

// request mediaElementAttributes option
const attributes = root.query('GET_MEDIA_ELEMENT_ATTRIBUTES');

// get all keys from attributes object
const attrsList = Object.keys(attributes);

// get item
const item = root.query('GET_ITEM', { id: props.id });
let tagName = isPreviewableAudio(item.file) ? 'audio' : 'video';

root.ref.media = document.createElement(tagName);
root.ref.media.setAttribute('controls', true);

// map through all given attributes and set'em
attrsList.forEach(attribute => {
// null and false attributes' values won't be passed
// as soon as text is considered as truthy value and false
// being passed in setAttribute will be converted to string.
// Note: 0 is false, but it still can be treated as truthy value.
if (typeof attributes[attribute] === "undefined" || attributes[attribute] === null) return;

root.ref.media.setAttribute(attribute, attributes[attribute]);
})

root.element.appendChild(root.ref.media);

if (isPreviewableAudio(item.file)) {
Expand Down

0 comments on commit 82df148

Please sign in to comment.