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

feat: shuffle slides (v2) #745

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion src/components/ItaliaTheme/Blocks/Listing/SliderTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import PropTypes from 'prop-types';
import { UniversalLink } from '@plone/volto/components';
import cx from 'classnames';
import { injectLazyLibs } from '@plone/volto/helpers/Loadable/Loadable';
import {shuffle} from 'lodash';

const messages = defineMessages({
viewImage: {
Expand Down Expand Up @@ -206,6 +207,7 @@ const SliderTemplate = ({
show_dots = true,
autoplay = false,
autoplay_speed = 2, //seconds
shuffle_items = false,
reactSlick,
}) => {
const intl = useIntl();
Expand Down Expand Up @@ -345,7 +347,7 @@ const SliderTemplate = ({
)}

<Slider {...settings} ref={slider}>
{items.map((item, index) => {
{(shuffle_items ? shuffle(items) : items).map((item, index) => {
const image = ListingImage({
item,
loading: index === 0 ? 'eager' : 'lazy',
Expand Down
16 changes: 16 additions & 0 deletions src/config/Blocks/ListingOptions/sliderTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const messages = defineMessages({
id: 'autoplay_speed_description',
defaultMessage: 'La velocità di autoplay deve essere espressa in secondi.',
},
shuffle_items: {
id: 'shuffle_items',
defaultMessage:
'Ordine casuale (in caso di paginazione solo la prima pagina sarà ordinata casualmente)',
},
});

export const addSliderTemplateOptions = (
Expand Down Expand Up @@ -99,5 +104,16 @@ export const addSliderTemplateOptions = (
{ type: 'number', default: 1 },
pos,
);
pos++;

addSchemaField(
schema,
'shuffle_items',
intl.formatMessage(messages.shuffle_items),
null,
{ type: 'boolean', default: false },
pos,
);

return pos;
};
Loading