Skip to content

Commit cd4cfa5

Browse files
authored
Merge pull request #17 from Voog/013-block-settings
Add page height & full width options to blocks
2 parents 1d520d4 + 01914d1 commit cd4cfa5

File tree

8 files changed

+198
-52
lines changed

8 files changed

+198
-52
lines changed

components/block-structure.tpl

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@
5858
{{ background_key }}-picker-area
5959
js-background-type
6060
{{ bg_type }}
61-
{% if content_class -%}{{ content_class }}{%- endif -%}
62-
{% if animated -%}animated js-animated-block{%- endif -%}
61+
{% if page_height %}page-height{% endif %}
62+
{% if full_width %}full-width{% endif %}
63+
{% if content_class -%}{{ content_class }}{%- endif %}
64+
{% if animated -%}animated js-animated-block{%- endif %}
6365
"
6466
data-block-key="{{ id }}"
6567
>

components/block.tpl

+57-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
{%- assign id = block_data.key -%}
22
{%- assign content_area_count = layout_data.content_areas | default: 1 -%}
33

4+
{%- assign page_height = block_data.settings.page_height -%}
5+
6+
{% if page_height == null -%}
7+
{%- assign page_height = true -%}
8+
{% endif -%}
9+
10+
{% assign full_width = block_data.settings.full_width -%}
11+
12+
{% if full_width == null -%}
13+
{%- assign full_width = false -%}
14+
{% endif -%}
15+
416
{%- capture move_buttons -%}
517
<button
618
class="move-button up-button js-move-button"
@@ -27,6 +39,44 @@
2739
></button>
2840
{%- endcapture -%}
2941

42+
{%- capture settings_options -%}
43+
<div class="settings-options">
44+
<div class="settings-checkbox">
45+
<label>
46+
<input
47+
type="checkbox"
48+
class="js-settings-checkbox"
49+
data-key="{{ id }}"
50+
data-setting="page_height"
51+
{% if page_height %}
52+
checked
53+
{% endif %}
54+
/>
55+
56+
{{ "full_height" | lce }}
57+
</label>
58+
</div>
59+
60+
{% if layout_name == "column" -%}
61+
<div class="settings-checkbox">
62+
<label>
63+
<input
64+
type="checkbox"
65+
class="js-settings-checkbox"
66+
data-key="{{ id }}"
67+
data-setting="full_width"
68+
{% if full_width %}
69+
checked
70+
{% endif %}
71+
/>
72+
73+
{{ "max_width" | lce }}
74+
</label>
75+
</div>
76+
{% endif -%}
77+
</div>
78+
{%- endcapture -%}
79+
3080
{%- capture change_layout_options -%}
3181
{%- if allowed_layouts.size > 1 -%}
3282
<div class="change-layout-options" data-title="{{ 'change_content_layout' | lce }}">
@@ -74,6 +124,7 @@
74124
{{ move_buttons }}
75125
{{ delete_button }}
76126
{{ change_layout_options }}
127+
{{ settings_options }}
77128
</div>
78129
{%- endif %}
79130

@@ -97,7 +148,9 @@
97148
content_class: content_class,
98149
id: id,
99150
layout_name: layout_name,
100-
separate_bg_pickers: layout_data.separate_bg_pickers
151+
separate_bg_pickers: layout_data.separate_bg_pickers,
152+
full_width: full_width,
153+
page_height: page_height
101154
-%}
102155
{% endfor %}
103156
{%- else -%}
@@ -117,7 +170,9 @@
117170
content_class: content_class,
118171
id: id,
119172
layout_name: layout_name,
120-
separate_bg_pickers: layout_data.separate_bg_pickers
173+
separate_bg_pickers: layout_data.separate_bg_pickers,
174+
full_width: full_width,
175+
page_height: page_height
121176
%}
122177
{% endif %}
123178
</div>

javascripts/editmode.js

+20
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,32 @@
397397
});
398398
};
399399

400+
const bindBlockSettingsButton = ({bodyBlocks, dataKey}) => {
401+
$('.js-settings-checkbox').on('change', e => {
402+
const targetKey = e.target.dataset.key;
403+
const settingKey = e.target.dataset.setting;
404+
const currentBlock = bodyBlocks.find(block => String(block.key) === String(targetKey));
405+
406+
const $currentBlockElement = $(`[data-block-key="${targetKey}"]`);
407+
408+
currentBlock.settings = currentBlock.settings || {};
409+
currentBlock.settings[settingKey] = e.target.checked;
410+
411+
pageData.set(dataKey, bodyBlocks);
412+
413+
$currentBlockElement.find('.block').each((_, block) => {
414+
$(block).toggleClass(settingKey.replace(/_/g, '-'), e.target.checked);
415+
});
416+
});
417+
};
418+
400419
const bindBlockActions = ({bodyBlocks, dataKey, deleteConfirmation}) => {
401420
$(document).ready(() => {
402421
bindBlockAdd({bodyBlocks, dataKey});
403422
bindBlockDelete({bodyBlocks, dataKey, deleteConfirmation});
404423
bindBlockReorder({bodyBlocks, dataKey});
405424
bindBlockLayoutChange({bodyBlocks, dataKey});
425+
bindBlockSettingsButton({bodyBlocks, dataKey});
406426
});
407427
};
408428

javascripts/editmode.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sources/javascripts/editmode.js

+20
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,32 @@
393393
});
394394
};
395395

396+
const bindBlockSettingsButton = ({bodyBlocks, dataKey}) => {
397+
$('.js-settings-checkbox').on('change', e => {
398+
const targetKey = e.target.dataset.key;
399+
const settingKey = e.target.dataset.setting;
400+
const currentBlock = bodyBlocks.find(block => String(block.key) === String(targetKey));
401+
402+
const $currentBlockElement = $(`[data-block-key="${targetKey}"]`);
403+
404+
currentBlock.settings = currentBlock.settings || {};
405+
currentBlock.settings[settingKey] = e.target.checked;
406+
407+
pageData.set(dataKey, bodyBlocks);
408+
409+
$currentBlockElement.find('.block').each((_, block) => {
410+
$(block).toggleClass(settingKey.replace(/_/g, '-'), e.target.checked);
411+
})
412+
});
413+
};
414+
396415
const bindBlockActions = ({bodyBlocks, dataKey, deleteConfirmation}) => {
397416
$(document).ready(() => {
398417
bindBlockAdd({bodyBlocks, dataKey});
399418
bindBlockDelete({bodyBlocks, dataKey, deleteConfirmation});
400419
bindBlockReorder({bodyBlocks, dataKey});
401420
bindBlockLayoutChange({bodyBlocks, dataKey});
421+
bindBlockSettingsButton({bodyBlocks, dataKey});
402422
});
403423
};
404424

0 commit comments

Comments
 (0)