Skip to content

Commit c46d448

Browse files
committed
#636: Responsive breakpoint switcher - added script to pull mobile background image on mobile viewport
1 parent 540e1db commit c46d448

File tree

2 files changed

+39
-1
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+39
-1
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/banner/preview.js

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/banner/preview.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,26 @@ export default class Preview extends BasePreview {
512512
events.on(`image:${this.contentType.id}:uploadAfter`, () => {
513513
this.contentType.dataStore.set("background_type", "image");
514514
});
515+
events.on(`stage:${this.contentType.stageId}:viewportChangeAfter`, () => {
516+
const style = this.wrapper.getAttribute("style") ||
517+
this.wrapper.getAttribute("data-jarallax-original-styles");
518+
let backgroundImage;
519+
520+
if (!$(".desktop-viewport").length) {
521+
backgroundImage = this.contentType.dataStore.get("background_image");
522+
}
523+
if (!$(".mobile-viewport").length) {
524+
backgroundImage = this.contentType.dataStore.get("mobile_image");
525+
}
526+
527+
jarallax(this.wrapper, "destroy");
528+
this.wrapper.setAttribute("style", style);
529+
// @ts-ignore
530+
if (this.contentType.dataStore.get("background_type") as string !== "video" && backgroundImage.length) {
531+
// @ts-ignore
532+
this.wrapper.style.backgroundImage = `url(${backgroundImage[0].url})`;
533+
}
534+
});
515535
}
516536

517537
/**

0 commit comments

Comments
 (0)