.*?)' // Match & Capture all characters (lazy), can be empty
+ `(?=${anyLogicOperatorNonCapture}|$)`; // Looks ahead but does not capture the next logic operator
// Combine all matching patterns, separated by 'or' pipes
return new RegExp(
`${matchStartOfString}|${matchIfOperator}|${matchElseOperator}|${matchEndOperator}`,
'g'
);
}
/// ///////////////////////////////////////
// End of If Statement Processing Logic //
/// ///////////////////////////////////////
/**
*
* @param copy
*/
export function doesCopyContainTextLink(copy) {
return copy.includes(dynamicStrings.TEXT_LINK);
}
/**
*
* @param context
*/
export function setupModalLinks(context) {
context.$nextTick(() => {
const elements = document.getElementsByClassName('modal-text');
for (const element of elements) {
const target = element.getAttribute('modalTarget');
if (target) {
element.addEventListener('click', () => context.$refs[target].openModal());
}
}
});
}
/**
*
* @param context
* @param desiredTarget
*/
export function setupModalLink(context, desiredTarget) {
context.$nextTick(() => {
const element = document.querySelector(`[modalTarget=${desiredTarget}]`);
if (element) {
element.addEventListener('click', () => context.$refs[desiredTarget].openModal());
}
});
}
/**
*
* @param copy
*/
export function doesCopyContainRouterLink(copy) {
return copy.includes(this.dynamicStrings.ROUTER_LINK);
}
/**
* splits copy on { ... } such as {routerlink: ...}
* @param copy
* @returns array of strings
*/
export function splitCopyOnCMSPlaceHolder(copy) {
// splits copy on { ... } such as {routerlink: ...}
return copy.split(/{(.*?)}/g);
}
export function getExternalLink(copy) {
const url = copy.split(':')[1].split(',')[0];
if (url.includes('https-')) {
const prefixAdded = url.replace('https-', 'https://');
return prefixAdded;
}
return '#!';
}
/**
* Returns string2 of input following this pattern: {string1:string2,string3}
* @param copy
* @returns string
*/
export function getRouterLinkRouteFromCopy(copy) {
// sample input: {routerLink:estimate,provide your VIN}
// first split would return 'estimate,provide your VIN'
// second split would return 'estimate'
return copy.split(':')[1].split(',')[0];
}
/**
* Returns string3 of input following this pattern: { string1: string2, string3 }
* @param copy
* @returns string
*/
export function getRouterLinkDisplayTextFromCopy(copy) {
// sample input: {routerLink:estimate,provide your VIN}
// first split would return 'estimate,provide your VIN'
// second split would return 'provide your VIN'
return copy.split(':')[1].split(',')[1];
}
/**
* Returns a router link as an 'a' tag element
* @param copy
* @returns string
*/
export function getRouterLinkHtmlStringFromCopy(copy) {
return `${getRouterLinkDisplayTextFromCopy(copy)}`;
}
// Copy returned from the CMS that has newlines will return blocks wrapped in
// ...
// This function returns an array of each paragraph, works with or without html
// attributes present
/**
*
* @param copy
*/
export function splitCMSCopyOnParagraphTag(copy) {
// filter removes empty strings that are a result of string.split with regex
return copy.split(/(?:)|(?:<\/p>)/g).filter((paragraph) => paragraph !== '');
}