diff --git a/assets/carousel/frontblocks-advanced-option.js b/assets/carousel/frontblocks-advanced-option.js index a5191eb..c61355e 100644 --- a/assets/carousel/frontblocks-advanced-option.js +++ b/assets/carousel/frontblocks-advanced-option.js @@ -47,6 +47,8 @@ function addCustomCarouselPanel(BlockEdit) { frblResponsiveToView = _props$attributes$frb5 === void 0 ? '1' : _props$attributes$frb5, _props$attributes$frb6 = _props$attributes.frblAutoplay, frblAutoplay = _props$attributes$frb6 === void 0 ? '' : _props$attributes$frb6, + _props$attributes$frbGap = _props$attributes.frblGap, + frblGap = _props$attributes$frbGap === void 0 ? '20' : _props$attributes$frbGap, _props$attributes$frb7 = _props$attributes.frblButtons, frblButtons = _props$attributes$frb7 === void 0 ? 'arrows' : _props$attributes$frb7, _props$attributes$frb8 = _props$attributes.frblRewind, @@ -123,6 +125,15 @@ function addCustomCarouselPanel(BlockEdit) { frblAutoplay: value }); } + }), /*#__PURE__*/React.createElement(TextControl, { + label: __('Gap (px)', 'frontblocks'), + value: frblGap, + onChange: function onChange(value) { + return props.setAttributes({ + frblGap: value + }); + }, + help: __('Space between slides in pixels. Leave empty for 20.', 'frontblocks') }), frblGridOption === 'slider' && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ToggleControl, { label: __('Rewind', 'frontblocks'), checked: frblRewind, diff --git a/assets/carousel/frontblocks-advanced-option.jsx b/assets/carousel/frontblocks-advanced-option.jsx index ae46d89..6bfd2ef 100644 --- a/assets/carousel/frontblocks-advanced-option.jsx +++ b/assets/carousel/frontblocks-advanced-option.jsx @@ -37,6 +37,7 @@ function addCustomCarouselPanel(BlockEdit) { frblTabletToView = '2', frblResponsiveToView = '1', frblAutoplay = '', + frblGap = '20', frblButtons = 'arrows', frblRewind = true, frblButtonColor, @@ -97,6 +98,12 @@ function addCustomCarouselPanel(BlockEdit) { value={frblAutoplay} onChange={(value) => props.setAttributes({ frblAutoplay: value })} /> + props.setAttributes({ frblGap: value })} + help={__('Space between slides in pixels. Leave empty for 20.', 'frontblocks')} + /> {frblGridOption === 'slider' && ( <> * { - width: 100%; -} - -/* Ensure inner container doesn't interfere with carousel */ -.wp-block-group.frontblocks-carousel > .wp-block-group__inner-container { - display: block; - grid-template-columns: none; - gap: 0; - width: 100%; + display: block; + grid-template-columns: none; + gap: 0; } -/* Override grid styles for direct children in carousel mode */ -.glide__slides.wp-block-group, -.glide__slides.wp-block-group.is-layout-grid { - display: flex; - grid-template-columns: none; - gap: 0; - column-gap: 0; - row-gap: 0; +.wp-block-group.frontblocks-carousel .frontblocks.glide, +.wp-block-group.frontblocks-carousel .frontblocks .glide__track { + width: 100%; + max-width: 100%; + margin-left: 0; + margin-right: 0; + padding-left: 0; + padding-right: 0; } -/* Ensure slides have proper width */ -.glide__slides > .glide__slide { - min-width: 0; - flex-shrink: 0; +.wp-block-group.frontblocks-carousel > * { + width: 100%; } -/* Force full width for single slide view */ -.frontblocks-carousel[data-view="1"] .glide__slide { - margin-left: 0; - margin-right: 0; +.wp-block-group.frontblocks-carousel > .wp-block-group__inner-container { + display: block; + grid-template-columns: none; + gap: 0; + width: 100%; } -/* Remove gaps when showing one slide */ -.frontblocks-carousel[data-view="1"].glide__slides { - gap: 0; +.frontblocks .glide__slides.wp-block-group, +.frontblocks .glide__slides.wp-block-group.is-layout-grid { + display: flex; + grid-template-columns: none; + gap: 0; + column-gap: 0; + row-gap: 0; } -/* Responsive single slide view */ -@media only screen and (max-width: 768px) { - .frontblocks-carousel[data-mobile-view="1"] .glide__slide { - width: 100%; - flex: 0 0 100%; - max-width: 100%; - margin-left: 0; - margin-right: 0; - } -} - -@media only screen and (min-width: 769px) and (max-width: 1024px) { - .frontblocks-carousel[data-tablet-view="1"] .glide__slide { - width: 100%; - flex: 0 0 100%; - max-width: 100%; - margin-left: 0; - margin-right: 0; - } -} - -@media only screen and (min-width: 1025px) and (max-width: 1440px) { - .frontblocks-carousel[data-laptop-view="1"] .glide__slide { - width: 100%; - flex: 0 0 100%; - max-width: 100%; - margin-left: 0; - margin-right: 0; - } -} - -/* Handle alignfull content within carousel slides */ -.glide__slide > .wp-block-cover.alignfull, -.glide__slide > .alignfull { - width: 100%; - max-width: none; - margin-left: 0; - margin-right: 0; -} - -/* Ensure cover blocks maintain minimum height */ -.glide__slide .wp-block-cover { - min-height: 430px; - display: flex; - align-items: center; - justify-content: center; -} - -/* Prevent carousel from overflowing viewport */ -.glide { - position: relative; - overflow: visible; - min-height: 430px; -} - -.glide__track { - overflow: hidden; - width: 100%; - position: relative; - z-index: 1; -} - -.glide__slides { - position: relative; - z-index: 1; - height: auto; - min-height: 430px; -} - -.glide__slide { - position: relative; - z-index: 1; - height: auto; - opacity: 1; - visibility: visible; +.frontblocks .glide__slides > .glide__slide { + min-width: 0; + flex-shrink: 0; } diff --git a/assets/carousel/frontblocks-carousel.js b/assets/carousel/frontblocks-carousel.js index 8d5008e..c673414 100644 --- a/assets/carousel/frontblocks-carousel.js +++ b/assets/carousel/frontblocks-carousel.js @@ -28,7 +28,7 @@ window.addEventListener('load', function (event) { parentwrap.replaceChild(wrapperParent, wrapper); wrapperParent.appendChild(wrapper); - wrapperParent.classList.add('glide'); + wrapperParent.classList.add('frontblocks', 'glide'); // Options const carouselType = item.getAttribute('data-type') ? item.getAttribute('data-type') : 'carousel'; @@ -37,8 +37,9 @@ window.addEventListener('load', function (event) { const carouselLaptopView = item.getAttribute('data-laptop-view') ? parseInt(item.getAttribute('data-laptop-view')) : 3; const carouselTabletView = item.getAttribute('data-tablet-view') ? parseInt(item.getAttribute('data-tablet-view')) : 2; const carouselMobileView = item.getAttribute('data-mobile-view') ? parseInt(item.getAttribute('data-mobile-view')) : 1; - const autoplayValue = item.getAttribute('data-autoplay'); - const carouselAutoplay = autoplayValue && autoplayValue !== '' ? parseInt(autoplayValue) : 0; + const autoplayAttr = item.getAttribute('data-autoplay'); + const carouselAutoplay = (autoplayAttr !== '' && autoplayAttr !== null && autoplayAttr !== undefined) ? parseInt(autoplayAttr, 10) : 0; + const carouselGap = item.getAttribute('data-gap') ? parseInt(item.getAttribute('data-gap'), 10) : 20; const carouselRewind = item.getAttribute('data-rewind') ? item.getAttribute('data-rewind') : false; const carouselbuttonsColor = item.getAttribute('data-buttons-color') ? item.getAttribute('data-buttons-color') : 'black'; const carouselbuttonsBackgroundColor = item.getAttribute('data-buttons-background-color') ? item.getAttribute('data-buttons-background-color') : 'transparent'; @@ -78,8 +79,8 @@ window.addEventListener('load', function (event) { // Add custom CSS for active bullet color const style = document.createElement('style'); style.textContent = ` - .glide__bullet.glide__bullet--active { - background-color: ${carouselbuttonsColor} !important; + .frontblocks .glide__bullet.glide__bullet--active { + background-color: ${carouselbuttonsColor}; } `; document.head.appendChild(style); @@ -109,28 +110,22 @@ window.addEventListener('load', function (event) { arrows.innerHTML = arrowsHTML; wrapperParent.appendChild(arrows); } - // Calculate gap based on perView - use 0 gap when showing 1 slide - const calculateGap = (view) => view === 1 ? 0 : 20; - const glideFrontBlocks = new Glide(wrapperParent, { type: carouselType, perView: carouselView, startAt: 0, - autoplay: carouselAutoplay === 0 ? false : carouselAutoplay, - gap: calculateGap(carouselView), + autoplay: carouselAutoplay > 0 ? carouselAutoplay : false, + gap: isNaN(carouselGap) ? 20 : carouselGap, rewind: carouselRewind, breakpoints: { 768: { - perView: carouselMobileView, - gap: calculateGap(carouselMobileView) + perView: carouselMobileView }, 1024: { - perView: carouselTabletView, - gap: calculateGap(carouselTabletView) + perView: carouselTabletView }, 1440: { - perView: carouselLaptopView, - gap: calculateGap(carouselLaptopView) + perView: carouselLaptopView } } }); @@ -153,4 +148,4 @@ window.addEventListener('load', function (event) { glideFrontBlocks.mount(); }); } -}); \ No newline at end of file +}); diff --git a/includes/Frontend/Carousel.php b/includes/Frontend/Carousel.php index 742fd40..421afc3 100644 --- a/includes/Frontend/Carousel.php +++ b/includes/Frontend/Carousel.php @@ -75,6 +75,7 @@ public function add_custom_attributes_to_grid_block( $block_content, $block ) { $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2; $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1; $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : ''; + $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20; $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true; $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows'; $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : ''; @@ -99,6 +100,7 @@ public function add_custom_attributes_to_grid_block( $block_content, $block ) { ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' . ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' . ' data-autoplay="' . esc_attr( $autoplay ) . '"' . + ' data-gap="' . esc_attr( $gap ) . '"' . ' data-buttons="' . esc_attr( $buttons ) . '"' . ' data-buttons-color="' . esc_attr( $button_color ) . '"' . ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' . @@ -139,6 +141,7 @@ public function add_custom_attributes_to_element_block( $block_content, $block ) $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2; $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1; $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : ''; + $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20; $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true; $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows'; $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : ''; @@ -163,6 +166,7 @@ public function add_custom_attributes_to_element_block( $block_content, $block ) ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' . ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' . ' data-autoplay="' . esc_attr( $autoplay ) . '"' . + ' data-gap="' . esc_attr( $gap ) . '"' . ' data-buttons="' . esc_attr( $buttons ) . '"' . ' data-buttons-color="' . esc_attr( $button_color ) . '"' . ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' . @@ -203,6 +207,7 @@ public function add_custom_attributes_to_core_group_block( $block_content, $bloc $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2; $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1; $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : ''; + $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20; $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true; $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows'; $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : ''; @@ -227,6 +232,7 @@ public function add_custom_attributes_to_core_group_block( $block_content, $bloc ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' . ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' . ' data-autoplay="' . esc_attr( $autoplay ) . '"' . + ' data-gap="' . esc_attr( $gap ) . '"' . ' data-buttons="' . esc_attr( $buttons ) . '"' . ' data-buttons-color="' . esc_attr( $button_color ) . '"' . ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' . @@ -299,6 +305,10 @@ public function register_custom_attributes_for_grid_block( $block_args, $block_t 'type' => 'string', 'default' => '', ); + $block_args['attributes']['frblGap'] = array( + 'type' => 'string', + 'default' => '20', + ); $block_args['attributes']['frblRewind'] = array( 'type' => 'boolean', 'default' => true, @@ -370,6 +380,10 @@ function( settings, name ) { type: 'string', default: '' }, + frblGap: { + type: 'string', + default: '20' + }, frblButtons: { type: 'string', default: 'arrows'