Parse modalLink in CMS
This commit is contained in:
parent
33235224be
commit
d8173d54ba
2 changed files with 17 additions and 1 deletions
|
|
@ -2,7 +2,8 @@ const dynamicStrings = {
|
|||
GLOBAL_STATE: "globalState",
|
||||
CUSTOM: "custom",
|
||||
ROUTER_LINK: "routerLink:",
|
||||
TEXT_LINK: "textLink:"
|
||||
TEXT_LINK: "textLink:",
|
||||
MODAL_LINK: "modalLink:"
|
||||
};
|
||||
|
||||
export { dynamicStrings };
|
||||
|
|
@ -124,6 +124,9 @@ function processWidgetItemForReplacement(widgetModel, key) {
|
|||
if (widgetModel[key].includes(dynamicStrings.GLOBAL_STATE)) {
|
||||
widgetModel[key] = mapStringToState(widgetModel[key]);
|
||||
}
|
||||
if (widgetModel[key].includes(dynamicStrings.MODAL_LINK)) {
|
||||
widgetModel[key] = mapStringToModal(widgetModel[key]);
|
||||
}
|
||||
return widgetModel[key];
|
||||
}
|
||||
|
||||
|
|
@ -143,6 +146,18 @@ function processWidgetItemForReplacement(widgetModel, key) {
|
|||
return widgetModel[key];
|
||||
}
|
||||
|
||||
function mapStringToModal(str) {
|
||||
let startIndex = str.indexOf("{" + dynamicStrings.MODAL_LINK);
|
||||
let linkToReplace = str.substring(startIndex, str.length);
|
||||
linkToReplace = linkToReplace.substring(0, linkToReplace.indexOf("}") + 1);
|
||||
|
||||
let params = linkToReplace.substring((dynamicStrings.MODAL_LINK).length + 1, linkToReplace.length -1)
|
||||
let splitParams = params.split(",");
|
||||
let BodyText = '<a href="#!" data-bs-toggle="modal" data-bs-target="#' + splitParams[0] + '" aria-label="Modal window">' + splitParams[1] +'</a>'
|
||||
|
||||
return str.replace(linkToReplace, BodyText);
|
||||
}
|
||||
|
||||
// Function to convert a string, into a matching global state item.
|
||||
function mapStringToState(str) {
|
||||
// Pull all matches out of the string.
|
||||
|
|
|
|||
Loading…
Reference in a new issue