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

Feature/aspect ratio #10

Closed
wants to merge 3 commits into from
Closed
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
32 changes: 32 additions & 0 deletions view/adminhtml/pagebuilder/content_type/slider.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2024 Studio Raz. All rights reserved.
* See LICENSE for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_PageBuilder:etc/content_type.xsd">
<type name="slider">
<appearances>
<appearance name="default">
<elements>
<element name="main">
<style name="image_width_desktop"
source="css_var_image_width_desktop"
reader="SR_PageBuilder/js/property/css-variable-reader"/>
<style name="image_height_desktop"
source="css_var_image_height_desktop"
reader="SR_PageBuilder/js/property/css-variable-reader"/>
<style name="image_width_mobile"
source="css_var_image_width_mobile"
reader="SR_PageBuilder/js/property/css-variable-reader"/>
<style name="image_height_mobile"
source="css_var_image_height_mobile"
reader="SR_PageBuilder/js/property/css-variable-reader"/>
</element>
</elements>
</appearance>
</appearances>
</type>
</config>
47 changes: 47 additions & 0 deletions view/adminhtml/ui_component/pagebuilder_slider_form.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © 2024 Studio Raz. All rights reserved.
* See LICENSE for license details.
*/
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd" extends="pagebuilder_base_form">
<fieldset name="appearance_fieldset">
<field name="image_width_desktop" sortOrder="21" formElement="input">
<settings>
<label translate="true">Image Width Desktop</label>
<notice translate="true">Single number with no units</notice>
<validation>
<rule name="validate-number" xsi:type="boolean">true</rule>
</validation>
</settings>
</field>
<field name="image_height_desktop" sortOrder="22" formElement="input">
<settings>
<label translate="true">Image Height Desktop</label>
<notice translate="true">Single number with no units</notice>
<validation>
<rule name="validate-number" xsi:type="boolean">true</rule>
</validation>
</settings>
</field>
<field name="image_width_mobile" sortOrder="23" formElement="input">
<settings>
<label translate="true">Image Width Mobile</label>
<notice translate="true">Single number with no units</notice>
<validation>
<rule name="validate-number" xsi:type="boolean">true</rule>
</validation>
</settings>
</field>
<field name="image_height_mobile" sortOrder="24" formElement="input">
<settings>
<label translate="true">Image Height Mobile</label>
<notice translate="true">Single number with no units</notice>
<validation>
<rule name="validate-number" xsi:type="boolean">true</rule>
</validation>
</settings>
</field>
</fieldset>
</form>
18 changes: 18 additions & 0 deletions view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2024 Studio Raz. All rights reserved.
* See LICENSE for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="head.additional">
<block name="pagebuilder_slider_css_variables_ui" template="SR_PageBuilder::pagebuilder_slider_css_variables_styles.phtml"/>
</referenceBlock>
<referenceBlock name="before.body.end">
<block name="pagebuilder_slider_css_variables_ui2" template="SR_PageBuilder::pagebuilder_slider_css_variables_script.phtml"/>
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © 2024 Studio Raz. All rights reserved.
* See LICENSE for license details.
*/
declare(strict_types=1);

use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;

/**
* @var Template $block
* @var Escaper $escaper
*/
?>

<script>
(() => {
const elements = document.querySelectorAll('.pagebuilder-slider');
const cssVarNames = ['--image-width-desktop', '--image-height-desktop'];

Array.from(elements).forEach(element => {
const hasSize = cssVarNames.filter(cssVarName => {
return getComputedStyle(element).getPropertyValue(cssVarName).trim();
}).length === cssVarNames.length;

if (hasSize) {
element.classList.add('has-size');
}
});
})();
</script>

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © 2024 Studio Raz. All rights reserved.
* See LICENSE for license details.
*/
declare(strict_types=1);

use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;

/**
* @var Template $block
* @var Escaper $escaper
*/
?>

<style>
.pagebuilder-slider.has-size {
min-height: auto !important;
}

@media (max-width: 639px) {
.pagebuilder-slider.has-size [data-content-type="slide"],
.pagebuilder-slider.has-size .pagebuilder-slide-wrapper {
aspect-ratio: var(--image-width-mobile, var(--image-width-desktop)) / var(--image-height-mobile, var(--image-height-desktop));
}
}

@media (min-width: 640px) {
.pagebuilder-slider.has-size [data-content-type="slide"],
.pagebuilder-slider.has-size .pagebuilder-slide-wrapper {
aspect-ratio: var(--image-width-desktop) / var(--image-height-desktop);
}
}

.pagebuilder-slider.has-size .pagebuilder-slide-wrapper {
width: 100%;
min-height: auto !important;
}

.pagebuilder-slider.has-size [data-content-type="slide"] > div {
display: flex;
justify-content: center;
}

.pagebuilder-slider.has-size .pagebuilder-overlay {
min-height: auto !important;
}
</style>