From 9c626971c92d4a12665d7be16e725b8f03893535 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 5 Feb 2021 18:30:23 +0300 Subject: [PATCH] use mediaElementAttributes in createMediaView --- src/js/view/createMediaView.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/js/view/createMediaView.js b/src/js/view/createMediaView.js index 8df4ee3..6d01214 100644 --- a/src/js/view/createMediaView.js +++ b/src/js/view/createMediaView.js @@ -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)) {