Skip to content

Commit 339f963

Browse files
sobo-odooqsm-odoo
authored andcommitted
[IMP] web_editor, website: make Big Boxes snippet able to use grid mode
The grid mode allows some snippets to move and resize their columns in a grid. However, some of them were blocked because they don't look good in this mode. This is the case of the Big Boxes snippet: because it contains two blocks full of padding and since toggling the grid mode removes this padding, it ended looking weird. This commit allows the previously blocked Big Boxes snippet to toggle the grid mode. More generally, this commit allows snippets having only columns containing a background color to look good in grid mode by keeping a more logical padding for them. task-2973198 X-original-commit: a051922 Part-of: odoo#102525
1 parent 1a8c4dd commit 339f963

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

addons/web_editor/static/src/js/common/grid_layout_utils.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,20 @@ function _placeColumns(columnEls, rowSize, rowGap, columnSize, columnGap) {
134134
let maxRowEnd = 0;
135135
const columnSpans = [];
136136
const columnCount = columnEls.length; // number of column in the grid.
137+
const imageColumns = []; // array of boolean telling if it is a column with only an image.
138+
139+
// Checking if all the columns have a background color to take that into
140+
// account when computing their size and padding (to make them look good).
141+
const allBackgroundColor = [...columnEls].every(columnEl => columnEl.classList.contains('o_cc'));
142+
137143
for (const columnEl of columnEls) {
138144
const style = window.getComputedStyle(columnEl);
139145
// Horizontal placement.
140146
const columnLeft = columnEl.offsetLeft;
141147
// Getting the width of the column.
142148
const paddingLeft = parseFloat(style.paddingLeft);
143-
const width = parseFloat(columnEl.scrollWidth) - 2 * paddingLeft;
144-
const columnSpan = Math.ceil((width + columnGap) / (columnSize + columnGap));
149+
const width = parseFloat(columnEl.scrollWidth) - (allBackgroundColor ? 0 : 2 * paddingLeft);
150+
const columnSpan = Math.round((width + columnGap) / (columnSize + columnGap));
145151
const columnStart = Math.round(columnLeft / (columnSize + columnGap)) + 1;
146152
const columnEnd = columnStart + columnSpan;
147153

@@ -152,9 +158,9 @@ function _placeColumns(columnEls, rowSize, rowGap, columnSize, columnGap) {
152158
const paddingBottom = parseFloat(style.paddingBottom);
153159
const rowOffsetTop = Math.floor((paddingTop + rowGap) / (rowSize + rowGap));
154160
// Getting the height of the column.
155-
const height = parseFloat(columnEl.scrollHeight) - paddingTop - paddingBottom;
161+
const height = parseFloat(columnEl.scrollHeight) - (allBackgroundColor ? 0 : paddingTop + paddingBottom);
156162
const rowSpan = Math.ceil((height + rowGap) / (rowSize + rowGap));
157-
const rowStart = Math.round(columnTop / (rowSize + rowGap)) + 1 + rowOffsetTop;
163+
const rowStart = Math.round(columnTop / (rowSize + rowGap)) + 1 + (allBackgroundColor ? 0 : rowOffsetTop);
158164
const rowEnd = rowStart + rowSpan;
159165

160166
columnEl.style.gridArea = `${rowStart} / ${columnStart} / ${rowEnd} / ${columnEnd}`;
@@ -179,6 +185,17 @@ function _placeColumns(columnEls, rowSize, rowGap, columnSize, columnGap) {
179185
columnSpans.push(columnSpan);
180186
}
181187

188+
// If all the columns have a background color, set their padding to the
189+
// original padding of the first column.
190+
if (allBackgroundColor) {
191+
const style = window.getComputedStyle(columnEls[0]);
192+
const paddingY = style.paddingTop;
193+
const paddingX = style.paddingLeft;
194+
const rowEl = columnEls[0].parentNode;
195+
rowEl.style.setProperty('--grid-item-padding-y', paddingY);
196+
rowEl.style.setProperty('--grid-item-padding-x', paddingX);
197+
}
198+
182199
// Removing padding and offset classes.
183200
for (const [i, columnEl] of [...columnEls].entries()) {
184201
const regex = /^(pt|pb|col-|offset-)/;

addons/web_editor/static/src/js/editor/snippets.options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4443,7 +4443,7 @@ registry.sizing = SnippetOptionWidget.extend({
44434443
// Hiding the move handle for some snippets so we can't drag them
44444444
// and so we can't toggle the grid mode.
44454445
const moveHandleEl = this.$overlay[0].querySelector('.o_move_handle');
4446-
const untoggleableColumns = '.s_masonry_block, .s_showcase, .s_features_grid, .s_website_form, .s_color_blocks_2';
4446+
const untoggleableColumns = '.s_masonry_block, .s_showcase, .s_features_grid, .s_website_form';
44474447
const disableToggle = this.$target[0].closest(untoggleableColumns);
44484448
moveHandleEl.classList.toggle('d-none', disableToggle || isMobileView);
44494449

addons/web_editor/static/src/scss/web_editor.frontend.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
> * {
6161
width: 100%;
6262
margin: 0;
63-
padding: var(--grid-item-padding-y) var(--grid-item-padding-x);
63+
padding: var(--grid-item-padding-y) var(--grid-item-padding-x) !important;
6464
}
6565
}
6666

addons/web_editor/static/src/scss/wysiwyg_snippets.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,7 @@ we-button-group.o_grid {
25322532

25332533
// Background grid.
25342534
.o_we_background_grid {
2535-
padding: 0;
2535+
padding: 0 !important;
25362536
}
25372537

25382538
.o_we_cell {

addons/website/views/snippets/snippets.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@
477477
</div>
478478

479479
<div data-js="layout_column"
480-
data-selector="section.s_features_grid, section.s_color_blocks_2"
480+
data-selector="section.s_features_grid"
481481
data-target="> *:has(> .row:not(.s_nb_column_fixed)), > .s_allow_columns">
482482
<we-select string="Columns" data-no-preview="true">
483483
<we-button data-select-count="0" data-name="zero_cols_opt">None</we-button>
@@ -493,7 +493,7 @@
493493
<div data-js="layout_column"
494494
data-selector="section"
495495
data-target="> *:has(> .row:not(.s_nb_column_fixed)), > .s_allow_columns"
496-
data-exclude=".s_masonry_block, .s_features_grid, .s_color_blocks_2">
496+
data-exclude=".s_masonry_block, .s_features_grid">
497497
<we-row>
498498
<we-button-group string="Layout" data-no-preview="true">
499499
<we-button data-select-layout="grid" data-name="grid_mode">Grid</we-button>

0 commit comments

Comments
 (0)