Skip to content
Merged
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
35 changes: 31 additions & 4 deletions wp-content/plugins/vf-gutenberg/assets/vf-gutenberg.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
(() => {
const waitForSelector = (selector, parent, callback) => {
const existing = parent.querySelector(selector);
if (existing) {
callback(existing);
return;
}

const observer = new MutationObserver((records, observer) => {
for (const record of records) {
for (const node of record.addedNodes) {
if (node instanceof HTMLElement) {
if (node instanceof Element) {
if (node.matches(selector)) {
callback(node);
return;
}
const target = node.querySelector(selector);
if (target) {
callback(target);
return;
}
}
}
Expand Down Expand Up @@ -56,11 +67,27 @@

const iframes = new WeakMap();

const getPreviewRoot = (node) => {
return [...node.querySelectorAll('.vf-block')].find((preview) => {
return preview.closest('.wp-block[data-type^="acf/vf"]') === node;
});
};

const getDirectChild = (node, tagName) => {
return [...node.children].find((child) => child.tagName === tagName) || null;
};

const renderBlock = (node) => {
if (node.querySelector('.vf-block > iframe')) {
const block = getPreviewRoot(node);
if (!block) {
return;
}

if (getDirectChild(block, 'IFRAME')) {
return;
}
const template = node.querySelector(`.vf-block > template`);

const template = getDirectChild(block, 'TEMPLATE');
if (!template) {
requestAnimationFrame(() => {
renderBlock(node);
Expand Down Expand Up @@ -89,7 +116,7 @@
{once: true}
);

node.querySelector(`.vf-block`).appendChild(iframe);
block.appendChild(iframe);
iframes.set(node, iframe);

if (template.hasAttribute('data-is-container')) {
Expand Down
29 changes: 28 additions & 1 deletion wp-content/plugins/vf-gutenberg/vf-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ static function acf_render_template($args, $template, $acf_id = false) {
$block = $args[0];
$is_preview = $args[2];
$is_jsx = isset($block['supports']['jsx']) && $block['supports']['jsx'];
$is_plugin = isset($block['data']['is_plugin']) && (bool) $block['data']['is_plugin'];
if ( ! $acf_id) {
$acf_id = $block['id'];
}
Expand Down Expand Up @@ -336,6 +337,33 @@ static function acf_render_template($args, $template, $acf_id = false) {
return;
}

$is_inline_preview = false;
if ( ! $is_plugin) {
$template_path = is_string($template)
? wp_normalize_path($template)
: '';
$plugin_dir = wp_normalize_path(WP_PLUGIN_DIR) . '/';

if (
is_callable($template)
|| (
! empty($template_path)
&& strpos($template_path, $plugin_dir) === 0
)
) {
$is_inline_preview = true;
}
}

if ($is_inline_preview) {
?>
<div class="vf-block vf-block-preview" data-editing="false" data-loading="false">
<?php echo $html; ?>
</div>
<?php
return;
}

// Render iframe for admin preview
$is_container = (bool) get_field('is_container', $acf_id);

Expand All @@ -353,7 +381,6 @@ static function acf_render_template($args, $template, $acf_id = false) {
);

// Render using React if block is from a plugin
$is_plugin = isset($block['data']['is_plugin']) && (bool) $block['data']['is_plugin'];
if ($is_plugin) {
VF_Gutenberg::acf_render_template__deprecated($block, $template);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,36 @@
"ui_on_text": "",
"ui_off_text": ""
},
{
"key": "field_67ea9901b0a03",
"label": "Navigation menu",
"name": "vf_navigation_menu",
"type": "select",
"instructions": "Choose which menu to display when navigation is enabled.",
"required": 0,
"conditional_logic": [
[
{
"field": "field_621c9cc1c7da0",
"operator": "==",
"value": "1"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {},
"default_value": "",
"allow_null": 0,
"multiple": 0,
"ui": 1,
"return_format": "value",
"ajax": 0,
"placeholder": ""
},
{
"key": "field_621c9cc1c7e36",
"label": "Heading link",
Expand Down Expand Up @@ -239,5 +269,5 @@
"hide_on_screen": "",
"active": true,
"description": "VF-Hero container for blog pages",
"modified": 1646044300
}
"modified": 1774955400
}
15 changes: 15 additions & 0 deletions wp-content/plugins/vf-hero-container-custom-blog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function __construct(array $params = array()) {
'acf/settings/load_json',
array($this, 'acf_settings_load_json')
);
add_filter(
'acf/load_field/name=vf_navigation_menu',
array($this, 'acf_load_navigation_menu')
);
}

// public function template_callback($block, $content, $is_preview = false, $acf_id) {
Expand All @@ -50,6 +54,17 @@ public function acf_settings_load_json($paths) {
return $paths;
}

public function acf_load_navigation_menu($field) {
$field['choices'] = class_exists('VF_Navigation')
? VF_Navigation::get_navigation_menu_choices()
: array();
$field['default_value'] = class_exists('VF_Navigation')
? VF_Navigation::get_primary_menu_source()
: '';

return $field;
}

} // VF_WP_Hero_Blog

$plugin = new VF_WP_Hero_Blog(
Expand Down
10 changes: 9 additions & 1 deletion wp-content/plugins/vf-hero-container-custom-blog/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
$hero_subheading = get_field('vf_hero_subheading');
$hero_heading = get_field('vf_hero_heading');
$hero_url = get_field('vf_hero_url');
$navigation_enable = get_field('vf_navigation_enable');
$navigation_menu_source = class_exists('VF_Navigation')
? VF_Navigation::resolve_menu_source(get_field('vf_navigation_menu'))
: 'location:primary';

$spacing = get_field('vf_hero_spacing');
$spacing_class = "| vf-hero--";
Expand Down Expand Up @@ -91,4 +95,8 @@
</div>
</section>
<!--/vf-hero-->

<?php
if ($navigation_enable && class_exists('VF_Navigation')) {
VF_Navigation::render_menu($navigation_menu_source);
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,36 @@
"ui": 1,
"ui_on_text": "",
"ui_off_text": ""
},
{
"key": "field_67ea9901b0a02",
"label": "Navigation menu",
"name": "vf_navigation_menu",
"type": "select",
"instructions": "Choose which menu to display when navigation is enabled.",
"required": 0,
"conditional_logic": [
[
{
"field": "field_614326ab47614",
"operator": "==",
"value": "1"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {},
"default_value": "",
"allow_null": 0,
"multiple": 0,
"ui": 1,
"return_format": "value",
"ajax": 0,
"placeholder": ""
}
],
"location": [
Expand All @@ -239,5 +269,5 @@
"hide_on_screen": "",
"active": true,
"description": "VF-Hero container",
"modified": 1642150579
}
"modified": 1774955400
}
15 changes: 15 additions & 0 deletions wp-content/plugins/vf-hero-container-secondary/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function __construct(array $params = array()) {
'acf/settings/load_json',
array($this, 'acf_settings_load_json')
);
add_filter(
'acf/load_field/name=vf_navigation_menu',
array($this, 'acf_load_navigation_menu')
);
}

// public function template_callback($block, $content, $is_preview = false, $acf_id) {
Expand All @@ -50,6 +54,17 @@ public function acf_settings_load_json($paths) {
return $paths;
}

public function acf_load_navigation_menu($field) {
$field['choices'] = class_exists('VF_Navigation')
? VF_Navigation::get_navigation_menu_choices()
: array();
$field['default_value'] = class_exists('VF_Navigation')
? VF_Navigation::get_primary_menu_source()
: '';

return $field;
}

} // VF_WP_Hero_Secondary

$plugin = new VF_WP_Hero_Secondary(
Expand Down
10 changes: 9 additions & 1 deletion wp-content/plugins/vf-hero-container-secondary/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
$hero_subheading = get_field('vf_hero_subheading');
$hero_heading = get_field('vf_hero_heading');
$hero_url = get_field('vf_hero_url');
$navigation_enable = get_field('vf_navigation_enable');
$navigation_menu_source = class_exists('VF_Navigation')
? VF_Navigation::resolve_menu_source(get_field('vf_navigation_menu'))
: 'location:primary';

$spacing = get_field('vf_hero_spacing');
$spacing_class = "| vf-hero--";
Expand Down Expand Up @@ -91,4 +95,8 @@
</div>
</section>
<!--/vf-hero-->

<?php
if ($navigation_enable && class_exists('VF_Navigation')) {
VF_Navigation::render_menu($navigation_menu_source);
}
?>
34 changes: 32 additions & 2 deletions wp-content/plugins/vf-hero-container/group_vf_wp_hero_group.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,36 @@
"ui": 1,
"ui_on_text": "",
"ui_off_text": ""
},
{
"key": "field_67ea9901b0a01",
"label": "Navigation menu",
"name": "vf_navigation_menu",
"type": "select",
"instructions": "Choose which menu to display when navigation is enabled.",
"required": 0,
"conditional_logic": [
[
{
"field": "field_603b3d040391d",
"operator": "==",
"value": "1"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {},
"default_value": "",
"allow_null": 0,
"multiple": 0,
"ui": 1,
"return_format": "value",
"ajax": 0,
"placeholder": ""
}
],
"location": [
Expand All @@ -244,5 +274,5 @@
"hide_on_screen": "",
"active": true,
"description": "VF-Hero container",
"modified": 1635940900
}
"modified": 1774955400
}
15 changes: 15 additions & 0 deletions wp-content/plugins/vf-hero-container/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function __construct(array $params = array()) {
'acf/settings/load_json',
array($this, 'acf_settings_load_json')
);
add_filter(
'acf/load_field/name=vf_navigation_menu',
array($this, 'acf_load_navigation_menu')
);
}

// public function template_callback($block, $content, $is_preview = false, $acf_id) {
Expand All @@ -50,6 +54,17 @@ public function acf_settings_load_json($paths) {
return $paths;
}

public function acf_load_navigation_menu($field) {
$field['choices'] = class_exists('VF_Navigation')
? VF_Navigation::get_navigation_menu_choices()
: array();
$field['default_value'] = class_exists('VF_Navigation')
? VF_Navigation::get_primary_menu_source()
: '';

return $field;
}

} // VF_WP_Hero

$plugin = new VF_WP_Hero(
Expand Down
Loading
Loading