Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the cld video player if its not included #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cartridges/int_cloudinary/cartridge/js/cloudinaryWidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ window.renderCloudinaryVideoPlayer = function () {
}
}
});
const targetNode = document.querySelector('#cld-video-player');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't we preventing the node from getting created at the first place?
Wouldn't we have the browser loading the VP widget and then discarding it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only happening in the case of custom mapping, in that scenario cartridge is creating URLs based on the configurations in custom mapping and it's not sure if the video is available in DOM before creating the URL, and I don't find any way to check if the video is available in DOM before rendering the video player

if (targetNode) {
const config = { childList: true, subtree: true };
const callback = function () {
if (targetNode.classList.contains('vjs-error')) {
observer.disconnect();
targetNode.remove(); // Remove the target node from the DOM
}
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
}

return cldURLs;
};
Expand All @@ -82,7 +94,7 @@ window.makeCloudinaryImagesResponsive = function () {
var $cldEl = $('.cloudinary-data-container');
var cloudinaryObj = $cldEl.data('cloudinary');
if ($cldResponsiveImgTags && $cldResponsiveImgTags.length > 0) {
if ( window.cldObj === undefined && window.cloudinary && window.cloudinary.default) {
if (window.cldObj === undefined && window.cloudinary && window.cloudinary.default) {
window.cldObj = window.cloudinary.default.Cloudinary.new({ cloud_name: cloudinaryObj.cloudName || cloudinaryObj });
}
window.cldObj && window.cldObj.responsive(); // eslint-disable-line no-undef
Expand Down