Skip to content

Commit cf223d0

Browse files
committed
#636: Responsive breakpoint switcher - worked on the requested changes
1 parent 1994997 commit cf223d0

File tree

13 files changed

+43
-275
lines changed

13 files changed

+43
-275
lines changed

app/code/Magento/PageBuilder/Component/Form/Element/Wysiwyg.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@
2626
*/
2727
class Wysiwyg extends \Magento\Ui\Component\Form\Element\Wysiwyg
2828
{
29+
/**
30+
* @var Repository
31+
*/
32+
private $assetRepo;
33+
2934
/**
3035
* WYSIWYG Constructor
3136
*
3237
* @param ContextInterface $context
3338
* @param FormFactory $formFactory
34-
* @param Repository $assetRepo
3539
* @param ConfigInterface $wysiwygConfig
3640
* @param CategoryAttributeRepositoryInterface $attrRepository
3741
* @param PageBuilderState $pageBuilderState
@@ -42,6 +46,7 @@ class Wysiwyg extends \Magento\Ui\Component\Form\Element\Wysiwyg
4246
* @param PageBuilderConfig|null $pageBuilderConfig
4347
* @param bool $overrideSnapshot
4448
* @param ViewConfigInterface $viewConfig
49+
* @param Repository $assetRepo
4550
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
4651
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4752
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -50,7 +55,6 @@ class Wysiwyg extends \Magento\Ui\Component\Form\Element\Wysiwyg
5055
public function __construct(
5156
ContextInterface $context,
5257
FormFactory $formFactory,
53-
Repository $assetRepo,
5458
ConfigInterface $wysiwygConfig,
5559
CategoryAttributeRepositoryInterface $attrRepository,
5660
PageBuilderState $pageBuilderState,
@@ -60,9 +64,11 @@ public function __construct(
6064
array $config = [],
6165
PageBuilderConfig $pageBuilderConfig = null,
6266
bool $overrideSnapshot = false,
63-
ViewConfigInterface $viewConfig = null
67+
ViewConfigInterface $viewConfig = null,
68+
Repository $assetRepo = null
6469
) {
6570
$viewConfig = $viewConfig ?: ObjectManager::getInstance()->get(ViewConfigInterface::class);
71+
$this->assetRepo = $assetRepo ?: ObjectManager::getInstance()->get(Repository::class);
6672
$wysiwygConfigData = isset($config['wysiwygConfigData']) ? $config['wysiwygConfigData'] : [];
6773

6874
// If a dataType is present we're dealing with an attribute
@@ -95,12 +101,7 @@ public function __construct(
95101
'Magento_PageBuilder',
96102
'breakpoints'
97103
);
98-
$wysiwygConfigData['viewports']['desktop']['icon'] = $assetRepo->getUrl(
99-
$wysiwygConfigData['viewports']['desktop']['icon']
100-
);
101-
$wysiwygConfigData['viewports']['mobile']['icon'] = $assetRepo->getUrl(
102-
$wysiwygConfigData['viewports']['mobile']['icon']
103-
);
104+
$wysiwygConfigData = $this->processBreakpointsIcons($wysiwygConfigData);
104105

105106
if ($overrideSnapshot) {
106107
$pageBuilderConfig = $pageBuilderConfig ?: ObjectManager::getInstance()->get(PageBuilderConfig::class);
@@ -125,4 +126,22 @@ public function __construct(
125126

126127
parent::__construct($context, $formFactory, $wysiwygConfig, $components, $data, $config);
127128
}
129+
130+
/**
131+
* Process viewport icon paths
132+
*
133+
* @param array $wysiwygConfigData
134+
* @return array
135+
*/
136+
private function processBreakpointsIcons(array $wysiwygConfigData): array
137+
{
138+
if ($wysiwygConfigData && isset($wysiwygConfigData['viewports'])) {
139+
foreach ($wysiwygConfigData['viewports'] as $breakpoint => $attributes) {
140+
if (isset($attributes['icon'])) {
141+
$wysiwygConfigData['viewports'][$breakpoint]['icon'] = $this->assetRepo->getUrl($attributes['icon']);
142+
}
143+
}
144+
}
145+
return $wysiwygConfigData;
146+
}
128147
}

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

Lines changed: 1 addition & 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/js/content-type/column/preview.js

Lines changed: 1 addition & 53 deletions
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/js/content-type/row/preview.js

Lines changed: 1 addition & 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/js/content-type/slide/preview.js

Lines changed: 1 addition & 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/js/content-type/tab-item/preview.js

Lines changed: 1 addition & 63 deletions
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/js/page-builder.js

Lines changed: 4 additions & 2 deletions
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ export default class Preview extends BasePreview {
531531
this.contentType.dataStore.set("background_type", "image");
532532
});
533533
events.on(`stage:${this.contentType.stageId}:viewportChangeAfter`, (args: {viewport: string}) => {
534-
if (this.contentType.dataStore.get("background_type") !== "video") {
534+
if (this.contentType.dataStore.get("background_type") === "video") {
535535
this.buildJarallax();
536536
}
537537
});

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

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ import {ContentTypeMountEventParamsInterface, ContentTypeMoveEventParamsInterfac
2121
import ObservableUpdater from "../observable-updater";
2222
import PreviewCollection from "../preview-collection";
2323
import {updateColumnWidth} from "./resize";
24-
import _ from "underscore";
2524

2625
/**
2726
* @api
2827
*/
2928
export default class Preview extends PreviewCollection {
3029
public resizing: KnockoutObservable<boolean> = ko.observable(false);
3130
public element: JQuery;
32-
private wrapper: HTMLElement;
3331

3432
/**
3533
* Fields that should not be considered when evaluating whether an object has been configured.
@@ -39,63 +37,6 @@ export default class Preview extends PreviewCollection {
3937
*/
4038
protected fieldsToIgnoreOnRemove: string[] = ["width"];
4139

42-
/**
43-
* Debounce and defer the init of Jarallax
44-
*
45-
* @type {(() => void) & _.Cancelable}
46-
*/
47-
private buildJarallax = _.debounce(() => {
48-
// Destroy all instances of the plugin prior
49-
try {
50-
// store/apply correct style after destroying, as jarallax incorrectly overrides it with stale value
51-
const style = this.wrapper.getAttribute("style") ||
52-
this.wrapper.getAttribute("data-jarallax-original-styles");
53-
const backgroundImage = this.getBackgroundImage();
54-
jarallax(this.wrapper, "destroy");
55-
this.wrapper.setAttribute("style", style);
56-
if (this.contentType.dataStore.get("background_type") as string !== "video" &&
57-
this.wrapper.style.backgroundImage !== backgroundImage &&
58-
backgroundImage !== "none"
59-
) {
60-
this.wrapper.style.backgroundImage = backgroundImage;
61-
}
62-
} catch (e) {
63-
// Failure of destroying is acceptable
64-
}
65-
66-
if (this.wrapper &&
67-
(this.wrapper.dataset.backgroundType as string) === "video" &&
68-
(this.wrapper.dataset.videoSrc as string).length
69-
) {
70-
_.defer(() => {
71-
// Build Parallax on elements with the correct class
72-
jarallax(
73-
this.wrapper,
74-
{
75-
videoSrc: this.wrapper.dataset.videoSrc as string,
76-
imgSrc: this.wrapper.dataset.videoFallbackSrc as string,
77-
videoLoop: (this.contentType.dataStore.get("video_loop") as string) === "true",
78-
speed: 1,
79-
videoPlayOnlyVisible: (this.contentType.dataStore.get("video_play_only_visible") as string) === "true",
80-
videoLazyLoading: (this.contentType.dataStore.get("video_lazy_load") as string) === "true",
81-
},
82-
);
83-
// @ts-ignore
84-
if (this.wrapper.jarallax && this.wrapper.jarallax.video) {
85-
// @ts-ignore
86-
this.wrapper.jarallax.video.on("started", () => {
87-
// @ts-ignore
88-
if (this.wrapper.jarallax && this.wrapper.jarallax.$video) {
89-
// @ts-ignore
90-
this.wrapper.jarallax.$video.style.visibility = "visible";
91-
}
92-
});
93-
}
94-
});
95-
}
96-
97-
}, 50);
98-
9940
/**
10041
* @param {ContentTypeInterface} contentType
10142
* @param {ContentTypeConfigInterface} config
@@ -149,12 +90,6 @@ export default class Preview extends PreviewCollection {
14990
}
15091
});
15192
}
152-
153-
events.on(`stage:${this.contentType.stageId}:viewportChangeAfter`, (args: {viewport: string}) => {
154-
if (this.contentType.dataStore.get("background_type") !== "video") {
155-
this.buildJarallax();
156-
}
157-
});
15893
}
15994

16095
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export default class Preview extends PreviewCollection {
144144
this.toggleFullScreen.bind(this),
145145
);
146146
events.on(`stage:${this.contentType.stageId}:viewportChangeAfter`, (args: {viewport: string}) => {
147-
if (this.contentType.dataStore.get("background_type") !== "video") {
147+
if (this.contentType.dataStore.get("background_type") === "video") {
148148
this.buildJarallax();
149149
}
150150
});

0 commit comments

Comments
 (0)