ConvertFieldAPIRulesToJoi.ts
2 years ago
PrepareFormData.ts
2 years ago
amountFormatter.ts
2 years ago
buildRegisterValidationOptions.ts
2 years ago
conditionOperatorFunctions.js
2 years ago
convertValuesToFormData.ts
2 years ago
createValidationObjectFromFields.js
2 years ago
generateRequestErrors.ts
1 year ago
getCurrentFormUrlData.js
1 year ago
getDefaultValuesFromSections.ts
2 years ago
getDonationFormNodeSettings.ts
2 years ago
getErrorByFieldName.ts
2 years ago
getWindowData.ts
2 years ago
groups.ts
2 years ago
handleFormRedirect.ts
1 year ago
handleFormSubmitRequest.ts
1 year ago
handleValidationRequest.ts
2 years ago
isRouteInlineRedirect.ts
2 years ago
memoNode.ts
2 years ago
mountWindowData.ts
1 year ago
postData.ts
2 years ago
postFormData.ts
2 years ago
registerFieldAndBuildProps.tsx
1 year ago
setDesignSettings.ts
2 years ago
useDonationFormPubSub.ts
1 year ago
setDesignSettings.ts
70 lines
| 1 | import {FormSettings} from '@givewp/form-builder/types'; |
| 2 | |
| 3 | /** |
| 4 | * @since 3.4.0 |
| 5 | */ |
| 6 | function updateDesignSettingsClassName(root: HTMLElement, block, element) { |
| 7 | root.classList.forEach((className) => { |
| 8 | if (className.startsWith(block + '__')) { |
| 9 | root.classList.remove(className); |
| 10 | } |
| 11 | }); |
| 12 | root.classList.add(block + '__' + element); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * @note currently not in use |
| 17 | * @since 3.4.0 |
| 18 | */ |
| 19 | export default function setDesignSettings(root: HTMLElement, settings: FormSettings) { |
| 20 | if (settings['designSettingsSectionStyle']) { |
| 21 | updateDesignSettingsClassName( |
| 22 | root, |
| 23 | 'givewp-design-settings--section-style', |
| 24 | settings['designSettingsSectionStyle'] |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | if (settings['designSettingsImageUrl']) { |
| 29 | root.style.setProperty( |
| 30 | '--givewp-design-settings-background-image', |
| 31 | 'url(' + settings['designSettingsImageUrl'] + ')' |
| 32 | ); |
| 33 | |
| 34 | const style = settings['designSettingsImageStyle'] ? settings['designSettingsImageStyle'] : 'background'; |
| 35 | |
| 36 | updateDesignSettingsClassName(root, 'givewp-design-settings--image-style', style); |
| 37 | } |
| 38 | |
| 39 | if (settings['designSettingsLogoUrl']) { |
| 40 | root.style.setProperty('--givewp-design-settings-logo', 'url(' + settings['designSettingsLogoUrl'] + ')'); |
| 41 | root.classList.add('givewp-design-settings--logo'); |
| 42 | |
| 43 | const position = settings['designSettingsLogoPosition'] ? settings['designSettingsLogoPosition'] : 'left'; |
| 44 | updateDesignSettingsClassName(root, 'givewp-design-settings--logo-position', position); |
| 45 | } |
| 46 | |
| 47 | if (settings['designSettingsTextFieldStyle']) { |
| 48 | updateDesignSettingsClassName( |
| 49 | root, |
| 50 | 'givewp-design-settings--textField-style', |
| 51 | settings['designSettingsTextFieldStyle'] |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | if (!settings['designSettingsImageUrl']) { |
| 56 | // reset/remove classnames on delete |
| 57 | root.style.setProperty('--givewp-design-settings-background-image', ''); |
| 58 | updateDesignSettingsClassName(root, 'givewp-design-settings--image-style', ''); |
| 59 | |
| 60 | // reconstruct branding container & logo container |
| 61 | root.classList.add('givewp-design-settings--logo'); |
| 62 | root.style.setProperty('--givewp-design-settings-logo', 'url(' + settings['designSettingsLogoUrl'] + ')'); |
| 63 | updateDesignSettingsClassName( |
| 64 | root, |
| 65 | 'givewp-design-settings--logo-position', |
| 66 | settings['designSettingsLogoPosition'] |
| 67 | ); |
| 68 | } |
| 69 | } |
| 70 |