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

Many improvements #19

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
77908e5
feat: setup poetry
fabien-michel Mar 2, 2023
3549c3e
feat: setup pre-commit
fabien-michel Mar 2, 2023
0386bec
chore: format all files with black and isort
fabien-michel Mar 2, 2023
4b1beae
fix: remove python2 compat code
fabien-michel Mar 2, 2023
b92be02
fix: explicit imports
fabien-michel Mar 2, 2023
6d85f57
feat: new AOS_INIT_PARAMS settings to define defaults instead of mode…
fabien-michel Mar 2, 2023
423154f
fix: get_aos_init_params_js in settings.py
fabien-michel Mar 3, 2023
f3d28a8
feat: add nullable instance param to specify mirror
fabien-michel Mar 3, 2023
7fc042a
feat: allow null value to once bool param (so it use default config)
fabien-michel Mar 3, 2023
c7cc75d
fix: default to collapse Anchor settings
fabien-michel Mar 3, 2023
6d500fa
feat: stripwhitespaces template tag to cleaner html output
fabien-michel Mar 3, 2023
2b0a97d
minor: comment on possible settings
fabien-michel Mar 3, 2023
d4dfb84
feat: upgrade aos statics (aos.css and aos.js)
fabien-michel Mar 3, 2023
903f642
feat: display default in widget value for ease and mirror
fabien-michel Mar 3, 2023
a91c390
feat: display default value in widget for easing and anchor_placement
fabien-michel Mar 3, 2023
b89413f
feat: display icon in edit mode to identify aos element and allow
fabien-michel Mar 3, 2023
7d138b3
feat: add french translation
fabien-michel Mar 3, 2023
3ff9c83
fix: helptext update
fabien-michel Mar 3, 2023
1244ed1
doc: add configuration section to README.rst
fabien-michel Mar 3, 2023
152dcb4
Update README.rst
fabien-michel Mar 3, 2023
017b98d
fix: gettext_lazy instead of deprecated ugettext_lazy
fabien-michel May 31, 2023
71187b9
chore: support django 4.1
fabien-michel May 31, 2023
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
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
exclude: "migrations/"
types: [python]

- repo: https://github.com/ambv/black
rev: 23.1.0
hooks:
- id: black
language_version: python3
exclude: "migrations/"
types: [python]
args: ["--config", "pyproject.toml"]
39 changes: 39 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,42 @@ Usage
-----

After installation simply add the plugins to the page.

Depending your configuration, you will probably need to specify the plugins in your `CMS_PLACEHOLDER_CONF` setting:

.. code:: python

CMS_PLACEHOLDER_CONF = {
'content': {
#...
'plugins': [
#...,
'AnimateOnScroll_Anchor_Plugin',
'AnimateOnScroll_Element_Plugin'
],
#...
},
}

Configuration
-------------

You can define the initial and default settings of AOS with the `AOS_INIT_PARAMS` setting:

.. code:: python

# settings.py

AOS_INIT_PARAMS = {
"easing": "ease",
"disable": False,
"offset": 120,
"duration": 400,
"delay": 0,
"once": False,
"mirror": False,
"anchor-placement": "top-bottom",
}


All settings from https://github.com/michalsnik/aos#1-initialize-aos can be specified.
3 changes: 1 addition & 2 deletions djangocms_animate_on_scroll/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
default_app_config = 'djangocms_animate_on_scroll.apps.DjangoCMS_AOS'

default_app_config = "djangocms_animate_on_scroll.apps.DjangoCMS_AOS"
7 changes: 4 additions & 3 deletions djangocms_animate_on_scroll/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.apps import AppConfig

class DjangoCMS_AOS(AppConfig): # Our app config class
name = 'djangocms_animate_on_scroll'
verbose_name = 'DjangoCMS Animate on Scroll'

class DjangoCMS_AOS(AppConfig): # Our app config class
name = "djangocms_animate_on_scroll"
verbose_name = "DjangoCMS Animate on Scroll"
97 changes: 51 additions & 46 deletions djangocms_animate_on_scroll/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,74 @@
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _
import json

from cms.plugin_pool import plugin_pool
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool

from django.utils.translation import gettext_lazy as _

from .models import AnimateOnScroll_Element, AnimateOnScroll_Anchor
from .forms import AnimateOnScroll_Element_Form
from .models import AnimateOnScroll_Anchor, AnimateOnScroll_Element
from .settings import get_aos_init_params_js


class AnimateOnScroll_Anchor_Plugin(CMSPluginBase):
model = AnimateOnScroll_Anchor
name = _('AnimateOnScroll - Anchor')
module = _('Animate On Scroll')
render_template = 'djangocms_animate_on_scroll/aos_anchor.html'
name = _("AnimateOnScroll - Anchor")
module = _("Animate On Scroll")
render_template = "djangocms_animate_on_scroll/aos_anchor.html"

fieldsets = (
(None, {
'fields': (
'id_name',
)
}),
)
fieldsets = ((None, {"fields": ("id_name",)}),)


plugin_pool.register_plugin(AnimateOnScroll_Anchor_Plugin)


class AnimateOnScroll_Element_Plugin(CMSPluginBase):
model = AnimateOnScroll_Element
name = _('AnimateOnScroll - Element')
module = _('Animate On Scroll')
render_template = 'djangocms_animate_on_scroll/aos_element.html'
name = _("AnimateOnScroll - Element")
module = _("Animate On Scroll")
render_template = "djangocms_animate_on_scroll/aos_element.html"
allow_children = True
form = AnimateOnScroll_Element_Form

fieldsets = (
(None, {
'fields': (
'aos_animation',
'aos_easing',
)
}),
(_('AOS Anchor settings'), {
'fields': (
'aos_anchor_placement',
'aos_anchor',
),
}),
(_('AOS Advanced settings'), {
'classes': ('collapse',),
'fields': (
('aos_offset',
'aos_duration',
'aos_delay',
'aos_once'),
),
}),
(_('Advanced Element settings'), {
'classes': ('collapse',),
'fields': (
'id_name',
'additional_classes',
'attributes',
),
}),
(
None,
{"fields": (("aos_animation", "aos_easing"),)},
),
(
_("AOS Anchor settings"),
{
"classes": ("collapse",),
"fields": (("aos_anchor_placement", "aos_anchor"),),
},
),
(
_("AOS Advanced settings"),
{
"classes": ("collapse",),
"fields": (
("aos_offset", "aos_duration", "aos_delay"),
("aos_once", "aos_mirror"),
),
},
),
(
_("Advanced Element settings"),
{
"classes": ("collapse",),
"fields": (
"id_name",
"additional_classes",
"attributes",
),
},
),
)

def render(self, context, instance, placeholder):
context = super().render(context, instance, placeholder)
context["aos_init_params"] = get_aos_init_params_js()
return context


plugin_pool.register_plugin(AnimateOnScroll_Element_Plugin)
130 changes: 65 additions & 65 deletions djangocms_animate_on_scroll/consts.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
AOS_ANIMATIONS = [
"fade",
"fade-up",
"fade-down",
"fade-left",
"fade-right",
"fade-up-right",
"fade-up-left",
"fade-down-right",
"fade-down-left",
"flip-up",
"flip-down",
"flip-left",
"flip-right",
"slide-up",
"slide-down",
"slide-left",
"slide-right",
"zoom-in",
"zoom-in-up",
"zoom-in-down",
"zoom-in-left",
"zoom-in-right",
"zoom-out",
"zoom-out-up",
"zoom-out-down",
"zoom-out-left",
"zoom-out-right",
]


AOS_ANIMATIONS = ['fade',
'fade-up',
'fade-down',
'fade-left',
'fade-right',
'fade-up-right',
'fade-up-left',
'fade-down-right',
'fade-down-left',
'flip-up',
'flip-down',
'flip-left',
'flip-right',
'slide-up',
'slide-down',
'slide-left',
'slide-right',
'zoom-in',
'zoom-in-up',
'zoom-in-down',
'zoom-in-left',
'zoom-in-right',
'zoom-out',
'zoom-out-up',
'zoom-out-down',
'zoom-out-left',
'zoom-out-right',
]
AOS_ANCHOR_PLACEMENT = [
None,
"top-bottom",
"top-center",
"top-top",
"center-bottom",
"center-center",
"center-top",
"bottom-bottom",
"bottom-center",
"bottom-top",
]


AOS_ANCHOR_PLACEMENT = [None,
'top-bottom',
'top-center',
'top-top',
'center-bottom',
'center-center',
'center-top',
'bottom-bottom',
'bottom-center',
'bottom-top',
]



AOS_EASING = [None,
'linear',
'ease',
'ease-in',
'ease-out',
'ease-in-out',
'ease-in-back',
'ease-out-back',
'ease-in-out-back',
'ease-in-sine',
'ease-out-sine',
'ease-in-out-sine',
'ease-in-quad',
'ease-out-quad',
'ease-in-out-quad',
'ease-in-cubic',
'ease-out-cubic',
'ease-in-out-cubic',
'ease-in-quart',
'ease-out-quart',
'ease-in-out-quart',
]
AOS_EASING = [
None,
"linear",
"ease",
"ease-in",
"ease-out",
"ease-in-out",
"ease-in-back",
"ease-out-back",
"ease-in-out-back",
"ease-in-sine",
"ease-out-sine",
"ease-in-out-sine",
"ease-in-quad",
"ease-out-quad",
"ease-in-out-quad",
"ease-in-cubic",
"ease-out-cubic",
"ease-in-out-cubic",
"ease-in-quart",
"ease-out-quart",
"ease-in-out-quart",
]

AOS_ANIMATIONS = ((a, a) for a in AOS_ANIMATIONS)
AOS_ANCHOR_PLACEMENT = ((a, a) for a in AOS_ANCHOR_PLACEMENT)
AOS_EASING = ((a, a) for a in AOS_EASING)
AOS_EASING = ((a, a) for a in AOS_EASING)
42 changes: 38 additions & 4 deletions djangocms_animate_on_scroll/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
from django.forms.models import ModelForm
from django import forms
from .consts import *
from django.forms.models import ModelForm
from django.utils.translation import gettext_lazy as _

from .consts import AOS_ANCHOR_PLACEMENT, AOS_ANIMATIONS, AOS_EASING
from .settings import get_aos_init_params

class AnimateOnScroll_Element_Form(ModelForm):

def choices_with_default_value(choices, default_value):
if isinstance(default_value, bool):
default_value = _("Yes") if default_value else _("No")
first_choice_str = f'{_("Default")} ({default_value})'
first_choice = (choices[0][0], first_choice_str)
return (first_choice, *choices[1:])


class AnimateOnScroll_Element_Form(ModelForm):
aos_animation = forms.ChoiceField(choices=AOS_ANIMATIONS)

aos_easing = forms.ChoiceField(choices=AOS_EASING, required=False)

aos_anchor_placement = forms.ChoiceField(choices=AOS_ANCHOR_PLACEMENT, required=False)
aos_anchor_placement = forms.ChoiceField(choices=AOS_ANCHOR_PLACEMENT, required=False)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
aoe_init_params = get_aos_init_params()

self.fields["aos_easing"].widget.choices = choices_with_default_value(
self.fields["aos_easing"].widget.choices, aoe_init_params["easing"]
)

self.fields["aos_anchor_placement"].widget.choices = choices_with_default_value(
self.fields["aos_anchor_placement"].widget.choices, aoe_init_params["anchor-placement"]
)

self.fields["aos_offset"].widget.attrs["placeholder"] = aoe_init_params["offset"]
self.fields["aos_duration"].widget.attrs["placeholder"] = aoe_init_params["duration"]
self.fields["aos_delay"].widget.attrs["placeholder"] = aoe_init_params["delay"]

self.fields["aos_once"].widget.choices = choices_with_default_value(
self.fields["aos_once"].widget.choices, aoe_init_params["once"]
)

self.fields["aos_mirror"].widget.choices = choices_with_default_value(
self.fields["aos_mirror"].widget.choices, aoe_init_params["mirror"]
)
Loading