PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
give / src / DonationForms / resources / app / utilities / setDesignSettings.ts

setDesignSettings.ts in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at src/DonationForms/resources/app/utilities/setDesignSettings.ts

70 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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