| 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 |
|