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

MWPW-161606 [MEP] Modify within modals with MEP #3171

Merged
merged 1 commit into from
Nov 8, 2024
Merged
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
13 changes: 4 additions & 9 deletions libs/blocks/fragment/fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,15 @@ const updateFragMap = (fragment, a, href) => {
}
};

const insertInlineFrag = (sections, a, relHref, mep, handleMepCommands) => {
const insertInlineFrag = (sections, a, relHref) => {
// Inline fragments only support one section, other sections are ignored
const fragChildren = [...sections[0].children];
if (a.parentElement.nodeName === 'DIV' && !a.parentElement.attributes.length) {
a.parentElement.replaceWith(...fragChildren);
} else {
a.replaceWith(...fragChildren);
}
fragChildren.forEach((child) => {
child.setAttribute('data-path', relHref);
if (handleMepCommands) mep.commands = handleMepCommands(mep.commands, child);
});
fragChildren.forEach((child) => child.setAttribute('data-path', relHref));
};

function replaceDotMedia(path, doc) {
Expand Down Expand Up @@ -132,16 +129,14 @@ export default async function init(a) {
const { updateFragDataProps } = await import('../../features/personalization/personalization.js');
updateFragDataProps(a, inline, sections, fragment);
}
let handleMepCommands = false;
if (mep?.commands?.length) {
const { handleCommands } = await import('../../features/personalization/personalization.js');
handleMepCommands = handleCommands;
handleCommands(mep?.commands, fragment, false, true);
}
if (inline) {
insertInlineFrag(sections, a, relHref, mep, handleMepCommands);
insertInlineFrag(sections, a, relHref, mep);
} else {
a.parentElement.replaceChild(fragment, a);
if (handleMepCommands) handleMepCommands(mep?.commands, fragment);
await loadArea(fragment);
}
}
Expand Down
Loading