Skip to content

Commit

Permalink
Fixing the saving of the slider and onsale values #377
Browse files Browse the repository at this point in the history
  • Loading branch information
krugazul committed Dec 5, 2024
1 parent 12e17fb commit f9e7883
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions assets/js/blocks/slider-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,22 @@
}

var hasCustomClass = props.attributes.hasCustomClass || false;
if ( undefined === props.attributes.hasCustomClass ) {
if ( props.attributes.className && props.attributes.className.includes( 'lsx-to-slider' ) ) {
hasCustomClass = true;
}
} else {
hasCustomClass = props.attributes.hasCustomClass;
}

var filterByOnsale = props.attributes.filterByOnsale || false;
if ( undefined === props.attributes.filterByOnsale ) {
if ( props.attributes.className && props.attributes.className.includes( 'on-sale' ) ) {
filterByOnsale = true;
}
} else {
filterByOnsale = props.attributes.filterByOnsale;
}

return el(
element.Fragment,
Expand All @@ -23,13 +38,14 @@
label: 'Enable Slider',
checked: hasCustomClass,
onChange: function (value) {
console.log(value);
props.setAttributes({
hasCustomClass: value
});
}
}),
el(CheckboxControl, {
label: 'Filter by Onsale',
label: 'Filter by On Sale',
checked: filterByOnsale,
onChange: function (value) {
props.setAttributes({
Expand All @@ -55,12 +71,20 @@
function (extraProps, blockType, attributes) {
if ( blockType.name === 'core/query' ) {

if (attributes.hasCustomClass) {
console.log(attributes.hasCustomClass);

if ( true === attributes.hasCustomClass ) {
extraProps.className = (extraProps.className || '') + ' lsx-to-slider';
console.log('adding');
} else if ( false === attributes.hasCustomClass && extraProps.className ) {
extraProps.className = extraProps.className.replace(/\blsx-to-slider\b\s*/g, '').trim();
console.log('removing');
}

if (attributes.filterByOnsale) {
if ( true === attributes.filterByOnsale ) {
extraProps.className = (extraProps.className || '') + ' on-sale';
} else if ( false === attributes.filterByOnsale && extraProps.className ) {
extraProps.className = extraProps.className.replace(/\bon-sale\b\s*/g, '').trim();
}

}
Expand Down

0 comments on commit f9e7883

Please sign in to comment.