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

fixed responsive issue on minicart and search suggestion #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

module.exports = function () {
// Custom Start: Make cart product images responsive //
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible that the minicart would be called twice, and we will create duplicate observers?
Maybe it makes sense to use a global DOM variable to skip a second call to the minicart

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 call once.

$('.minicart').bind('DOMSubtreeModified', function (e) {
if (e.target.innerHTML.length > 0) {
if (typeof window.makeCloudinaryImagesResponsive !== 'undefined') {
window.makeCloudinaryImagesResponsive();
}
}
});
const targetNode = document.querySelector('.minicart');
const config = { childList: true, subtree: true };

const callback = function () {
if (targetNode.innerHTML.length > 0 && typeof window.makeCloudinaryImagesResponsive !== 'undefined') {
window.makeCloudinaryImagesResponsive();
}
};

const observer = new MutationObserver(callback);
Copy link
Collaborator

Choose a reason for hiding this comment

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

MutationObserver - I like it!

observer.observe(targetNode, config);
// Custom End: Make cart product images responsive //
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ var baseSearch = require('base/components/search');
module.exports = function () {
baseSearch();
// Custom Start: Make suggested product images responsive //
$('.suggestions-wrapper').bind('DOMSubtreeModified', function (e) {
if (e.target.innerHTML.length > 0) {
if (typeof window.makeCloudinaryImagesResponsive !== 'undefined') {
window.makeCloudinaryImagesResponsive();
}
}
});
const targetNode = document.querySelector('.suggestions-wrapper');
const config = { childList: true, subtree: true };

const callback = function () {
if (targetNode.innerHTML.length > 0 && typeof window.makeCloudinaryImagesResponsive !== 'undefined') {
window.makeCloudinaryImagesResponsive();
}
};

const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
// Custom End: Make suggested product images responsive //
};