diff --git a/djangocms_frontend/contrib/carousel/cms_plugins.py b/djangocms_frontend/contrib/carousel/cms_plugins.py index 98eed47d..f9d421dc 100644 --- a/djangocms_frontend/contrib/carousel/cms_plugins.py +++ b/djangocms_frontend/contrib/carousel/cms_plugins.py @@ -6,6 +6,7 @@ from ... import settings from ...cms_plugins import CMSUIPlugin from ...common.attributes import AttributesMixin +from ...common.background import BackgroundMixin from .. import carousel from ..link.cms_plugins import LinkPluginMixin from . import forms, models @@ -37,7 +38,8 @@ class CarouselPlugin(mixin_factory("Carousel"), AttributesMixin, CMSUIPlugin): ("carousel_aspect_ratio", "carousel_interval"), ("carousel_controls", "carousel_indicators"), ("carousel_keyboard", "carousel_wrap"), - ("carousel_ride", "carousel_pause"), + ("carousel_ride",), + ("carousel_transition", "carousel_pause",), ) }, ), @@ -51,7 +53,7 @@ def get_render_template(self, context, instance, placeholder): @plugin_pool.register_plugin class CarouselSlidePlugin( - mixin_factory("CarouselSlide"), AttributesMixin, LinkPluginMixin, CMSUIPlugin + mixin_factory("CarouselSlide"), AttributesMixin, BackgroundMixin, LinkPluginMixin, CMSUIPlugin ): """ Components > "Carousel Slide" Plugin diff --git a/djangocms_frontend/contrib/carousel/constants.py b/djangocms_frontend/contrib/carousel/constants.py index 75a08025..54575003 100644 --- a/djangocms_frontend/contrib/carousel/constants.py +++ b/djangocms_frontend/contrib/carousel/constants.py @@ -2,15 +2,8 @@ from django.utils.translation import gettext_lazy as _ CAROUSEL_PAUSE_CHOICES = ( - ("hover", "hover"), - ("mouseenter", "mouseenter"), - ("mouseleave", "mouseleave"), - ("false", "off"), -) - -CAROUSEL_RIDE_CHOICES = ( - ("carousel", "carousel"), - ("false", "off"), + ("hover", _("On hover")), + ("false", _("Never")), ) CAROUSEL_TEMPLATE_CHOICES = getattr( @@ -38,3 +31,8 @@ CAROUSEL_ASPECT_RATIO_CHOICES = tuple( (f"{x}x{y}", f"{x}x{y}") for x, y in CAROUSEL_ASPECT_RATIOS ) + +CAROUSEL_TRANSITION_CHOICES = ( + ("", _("Slide")), + ("carousel-fade", _("Fade")), +) diff --git a/djangocms_frontend/contrib/carousel/forms.py b/djangocms_frontend/contrib/carousel/forms.py index 56d74886..482e2cec 100644 --- a/djangocms_frontend/contrib/carousel/forms.py +++ b/djangocms_frontend/contrib/carousel/forms.py @@ -7,11 +7,13 @@ from djangocms_frontend.fields import ( AttributesFormField, + ButtonGroup, TagTypeFormField, TemplateChoiceMixin, ) from ... import settings +from ...common.background import BackgroundFormMixin from ...fields import HTMLFormField from ...helpers import first_choice from ...models import FrontendUIItem @@ -20,8 +22,8 @@ from .constants import ( CAROUSEL_ASPECT_RATIO_CHOICES, CAROUSEL_PAUSE_CHOICES, - CAROUSEL_RIDE_CHOICES, CAROUSEL_TEMPLATE_CHOICES, + CAROUSEL_TRANSITION_CHOICES, ) mixin_factory = settings.get_forms(carousel) @@ -46,6 +48,7 @@ class Meta: "carousel_pause", "carousel_ride", "carousel_wrap", + "carousel_transition", "attributes", ] } @@ -93,11 +96,12 @@ class Meta: '"mouseleave". If set to "false", hovering over the carousel ' "won't pause it." ), + widget=ButtonGroup(attrs=dict(property="text")), ) - carousel_ride = forms.ChoiceField( - label=_("Ride"), - choices=CAROUSEL_RIDE_CHOICES, - initial=first_choice(CAROUSEL_RIDE_CHOICES), + carousel_ride = forms.BooleanField( + label=_("Auto start"), + initial=True, + required=False, help_text=_( "Autoplays the carousel after the user manually cycles the " 'first item. If "carousel", autoplays the carousel on load.' @@ -121,6 +125,16 @@ class Meta: "according to the selected ratio." ), ) + carousel_transition = forms.ChoiceField( + label=_("Transition"), + choices=CAROUSEL_TRANSITION_CHOICES, + required=False, + initial=CAROUSEL_TRANSITION_CHOICES[0][0], + help_text=_( + "Determines if slides change by sliding or fading." + ), + widget=ButtonGroup(attrs=dict(property="text")), + ) attributes = AttributesFormField( excluded_keys=[ "id", @@ -135,7 +149,7 @@ class Meta: class CarouselSlideForm( - mixin_factory("CarouselSlide"), AbstractLinkForm, EntangledModelForm + mixin_factory("CarouselSlide"), AbstractLinkForm, BackgroundFormMixin, EntangledModelForm ): """ Components > "Slide" Plugin @@ -160,6 +174,7 @@ class Meta: queryset=Image.objects.all(), to_field_name="id", label=_("Slide image"), + required=False, ) carousel_content = HTMLFormField( label=_("Content"), diff --git a/djangocms_frontend/contrib/carousel/frameworks/bootstrap5.py b/djangocms_frontend/contrib/carousel/frameworks/bootstrap5.py index e26275a5..b3460266 100644 --- a/djangocms_frontend/contrib/carousel/frameworks/bootstrap5.py +++ b/djangocms_frontend/contrib/carousel/frameworks/bootstrap5.py @@ -4,6 +4,8 @@ class CarouselRenderMixin: def render(self, context, instance, placeholder): instance.add_classes("carousel slide") + if instance.config.get("carousel_transition", None): + instance.add_classes(instance.carousel_transition) return super().render(context, instance, placeholder) diff --git a/djangocms_frontend/contrib/carousel/models.py b/djangocms_frontend/contrib/carousel/models.py index 3b96156a..0906ab2d 100644 --- a/djangocms_frontend/contrib/carousel/models.py +++ b/djangocms_frontend/contrib/carousel/models.py @@ -27,7 +27,7 @@ def get_short_description(self): text += ", {}: {}".format(_("Keyboard"), self.carousel_keyboard) text += ", {}: {}".format(_("Pause"), self.carousel_pause) text += ", {}: {}".format(_("Ride"), self.carousel_ride) - text += "{}: {}".format(_("Wrap"), self.carousel_wrap) + text += ", {}: {}".format(_("Wrap"), self.carousel_wrap) return text diff --git a/djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/carousel.html b/djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/carousel.html index dcd78dc6..abe0e164 100644 --- a/djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/carousel.html +++ b/djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/carousel.html @@ -4,7 +4,7 @@ data-bs-interval="{{ instance.carousel_interval|lower }}" data-bs-keyboard="{{ instance.carousel_keyboard|lower }}" data-bs-pause="{{ instance.carousel_pause|lower }}" - data-bs-ride="{{ instance.carousel_ride|lower }}" + data-bs-ride="{% if instance.carousel_ride %}carousel{% else %}false{% endif %}" data-bs-wrap="{{ instance.carousel_wrap|lower }}" > {% if instance.carousel_indicators %} diff --git a/djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/image.html b/djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/image.html index ba9fa9a4..cd6bdef4 100644 --- a/djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/image.html +++ b/djangocms_frontend/contrib/carousel/templates/djangocms_frontend/bootstrap5/carousel/default/image.html @@ -4,6 +4,10 @@ {% else %} -
+