Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wpforms-.../assets/js/admin/email
File: settings.js
/* global Choices, wpforms_admin_email_settings */
[0] Fix | Delete
/**
[1] Fix | Delete
* Script for manipulating DOM events in the "Email" settings page.
[2] Fix | Delete
* This script will be accessible in the "WPForms" → "Settings" → "Email" page.
[3] Fix | Delete
*
[4] Fix | Delete
* @since 1.8.5
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
const WPFormsEmailSettings = window.WPFormsEmailSettings || ( function( document, window, $, l10n ) {
[8] Fix | Delete
/**
[9] Fix | Delete
* Elements holder.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 1.8.5
[12] Fix | Delete
*
[13] Fix | Delete
* @type {Object}
[14] Fix | Delete
*/
[15] Fix | Delete
const el = {};
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Runtime variables.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 1.8.6
[21] Fix | Delete
*
[22] Fix | Delete
* @type {Object}
[23] Fix | Delete
*/
[24] Fix | Delete
const vars = {
[25] Fix | Delete
cache: {
[26] Fix | Delete
appearance: {
[27] Fix | Delete
light: '#email-appearance-light',
[28] Fix | Delete
},
[29] Fix | Delete
colors: {
[30] Fix | Delete
light: {
[31] Fix | Delete
background: [
[32] Fix | Delete
'#wpforms-setting-email-background-color',
[33] Fix | Delete
'#wpforms-setting-email-color-scheme-email_background_color',
[34] Fix | Delete
],
[35] Fix | Delete
text: '#wpforms-setting-email-color-scheme-email_text_color',
[36] Fix | Delete
},
[37] Fix | Delete
dark: {
[38] Fix | Delete
background: [
[39] Fix | Delete
'#wpforms-setting-email-background-color-dark',
[40] Fix | Delete
'#wpforms-setting-email-color-scheme-dark-email_background_color_dark',
[41] Fix | Delete
],
[42] Fix | Delete
text: '#wpforms-setting-email-color-scheme-dark-email_text_color_dark',
[43] Fix | Delete
},
[44] Fix | Delete
},
[45] Fix | Delete
},
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Generic CSS class names for applying visual changes.
[49] Fix | Delete
*
[50] Fix | Delete
* @since 1.8.6
[51] Fix | Delete
*/
[52] Fix | Delete
classNames: {
[53] Fix | Delete
hide: 'wpforms-hide',
[54] Fix | Delete
appearance: 'email-appearance-mode-toggle',
[55] Fix | Delete
legacyTemplate: 'legacy-template',
[56] Fix | Delete
hideForPlainText: 'hide-for-template-none',
[57] Fix | Delete
headerImage: 'wpforms-email-header-image',
[58] Fix | Delete
colorScheme: 'email-color-scheme',
[59] Fix | Delete
typography: 'email-typography',
[60] Fix | Delete
noticeWarning: 'notice-warning',
[61] Fix | Delete
noticeLegacy: 'wpforms-email-legacy-notice',
[62] Fix | Delete
settingsRow: 'wpforms-setting-row',
[63] Fix | Delete
settingField: 'wpforms-setting-field',
[64] Fix | Delete
},
[65] Fix | Delete
};
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Public functions and properties.
[69] Fix | Delete
*
[70] Fix | Delete
* @since 1.8.5
[71] Fix | Delete
*/
[72] Fix | Delete
const app = {
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Start the engine.
[76] Fix | Delete
*
[77] Fix | Delete
* @since 1.8.5
[78] Fix | Delete
*/
[79] Fix | Delete
init() {
[80] Fix | Delete
$( app.ready );
[81] Fix | Delete
},
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Document ready.
[85] Fix | Delete
*
[86] Fix | Delete
* @since 1.8.5
[87] Fix | Delete
*/
[88] Fix | Delete
ready() {
[89] Fix | Delete
app.setup();
[90] Fix | Delete
app.bindEvents();
[91] Fix | Delete
app.relocateImageSize();
[92] Fix | Delete
app.handleOnContrastChange();
[93] Fix | Delete
app.handleOnChangeBackgroundColor();
[94] Fix | Delete
},
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Setup. Prepare some variables.
[98] Fix | Delete
*
[99] Fix | Delete
* @since 1.8.5
[100] Fix | Delete
*/
[101] Fix | Delete
setup() {
[102] Fix | Delete
// Cache DOM elements.
[103] Fix | Delete
el.$wrapper = $( '.wpforms-admin-settings-email' );
[104] Fix | Delete
el.$appearance = $( `.${ vars.classNames.appearance }` );
[105] Fix | Delete
el.$colorScheme = $( `.${ vars.classNames.colorScheme }` );
[106] Fix | Delete
el.$typography = $( `.${ vars.classNames.typography }` );
[107] Fix | Delete
},
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Bind events.
[111] Fix | Delete
*
[112] Fix | Delete
* @since 1.8.5
[113] Fix | Delete
*/
[114] Fix | Delete
bindEvents() {
[115] Fix | Delete
el.$wrapper
[116] Fix | Delete
.on( 'change', '.wpforms-email-template input[type="radio"]', app.handleOnUpdateTemplate )
[117] Fix | Delete
.on( 'change', '.wpforms-email-header-image input', app.handleOnChangeHeaderImage )
[118] Fix | Delete
.on( 'click', '.wpforms-setting-remove-image', app.handleOnRemoveHeaderImage )
[119] Fix | Delete
.on( 'change', '.has-preview-changes :input', app.handleOnPreviewChanges )
[120] Fix | Delete
.on( 'change', '.email-appearance-mode-toggle input', app.handleOnAppearanceModeToggle )
[121] Fix | Delete
// Selectors for the following events are specified by matching the ID attribute by design to ensure both appearance modes are covered.
[122] Fix | Delete
.on( 'change', '[id*="email-background-color"], [id*="email_background_color"]', app.handleOnChangeBackgroundColor )
[123] Fix | Delete
.on( 'change', '[id*="email_body_color"], [id*="email_text_color"]', app.handleOnContrastChange );
[124] Fix | Delete
},
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Callback for template change.
[128] Fix | Delete
*
[129] Fix | Delete
* @since 1.8.5
[130] Fix | Delete
*
[131] Fix | Delete
* @param {Object} event An event which takes place in the DOM.
[132] Fix | Delete
*/
[133] Fix | Delete
handleOnUpdateTemplate( event ) {
[134] Fix | Delete
// Get the selected value from the event.
[135] Fix | Delete
const selected = $( event.currentTarget ).val();
[136] Fix | Delete
[137] Fix | Delete
// Find relevant elements in the wrapper.
[138] Fix | Delete
const $hideForNone = el.$wrapper.find( `.${ vars.classNames.hideForPlainText }` );
[139] Fix | Delete
const $imageSizeChoices = el.$wrapper.find( `.${ vars.classNames.headerImage } .choices` );
[140] Fix | Delete
const $backgroundControl = el.$wrapper.find( '.email-background-color' );
[141] Fix | Delete
const $legacyNotice = el.$wrapper.find( `.${ vars.classNames.noticeLegacy }` );
[142] Fix | Delete
const $educationModal = el.$wrapper.find( '.education-modal' );
[143] Fix | Delete
[144] Fix | Delete
// Check if it's a Pro template.
[145] Fix | Delete
const isPro = $educationModal.length === 0;
[146] Fix | Delete
[147] Fix | Delete
// Check if the selected value is 'none' or 'default'.
[148] Fix | Delete
const isNone = selected === 'none';
[149] Fix | Delete
const isDefault = selected === 'default';
[150] Fix | Delete
[151] Fix | Delete
// Toggle image size choices based on the selected value.
[152] Fix | Delete
$imageSizeChoices.each( ( i, elm ) => {
[153] Fix | Delete
const $this = $( elm );
[154] Fix | Delete
const hasImage = $this.closest( `.${ vars.classNames.settingField }` ).find( 'img' ).length;
[155] Fix | Delete
$this.toggle( ! isDefault && !! hasImage );
[156] Fix | Delete
} );
[157] Fix | Delete
[158] Fix | Delete
// Toggle visibility for elements based on conditions.
[159] Fix | Delete
$hideForNone.toggle( ! isNone );
[160] Fix | Delete
$legacyNotice.toggle( isDefault );
[161] Fix | Delete
$backgroundControl.toggle( ( isDefault || ! isPro ) && ! isNone );
[162] Fix | Delete
[163] Fix | Delete
// Toggle the light mode radio button based on the selected value.
[164] Fix | Delete
if ( isDefault ) {
[165] Fix | Delete
el.$appearance.find( vars.cache.appearance.light ).trigger( 'click' );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
// Cache the class name for the legacy template.
[169] Fix | Delete
const { legacyTemplate: legacyTemplateClassName } = vars.classNames;
[170] Fix | Delete
[171] Fix | Delete
// Toggle classes based on the selected value.
[172] Fix | Delete
el.$appearance.toggleClass( legacyTemplateClassName, isDefault );
[173] Fix | Delete
el.$colorScheme.toggleClass( legacyTemplateClassName, isDefault );
[174] Fix | Delete
el.$typography.toggleClass( legacyTemplateClassName, isDefault );
[175] Fix | Delete
[176] Fix | Delete
// Update the background color.
[177] Fix | Delete
app.handleOnChangeBackgroundColor();
[178] Fix | Delete
},
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Callback for "Upload Image" button click.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 1.8.6
[184] Fix | Delete
*/
[185] Fix | Delete
handleOnChangeHeaderImage() {
[186] Fix | Delete
// Update the background color.
[187] Fix | Delete
app.handleOnChangeBackgroundColor();
[188] Fix | Delete
[189] Fix | Delete
// In case the current template is "Legacy" or image tag doesn't exist, return early.
[190] Fix | Delete
if ( app.isLegacyTemplate() || ! $( this ).prev( 'img' ).length ) {
[191] Fix | Delete
return;
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
// Show the image size dropdown menu.
[195] Fix | Delete
$( this ).parent().find( '.choices' ).show();
[196] Fix | Delete
},
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Callback for "Remove Image" button click.
[200] Fix | Delete
*
[201] Fix | Delete
* @since 1.8.5
[202] Fix | Delete
*/
[203] Fix | Delete
handleOnRemoveHeaderImage() {
[204] Fix | Delete
$( this ).closest( `.${ vars.classNames.settingsRow }` ).removeClass( 'has-external-image-url' );
[205] Fix | Delete
},
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* Callback for the image size select input change.
[209] Fix | Delete
*
[210] Fix | Delete
* @since 1.8.5
[211] Fix | Delete
*/
[212] Fix | Delete
handleOnUpdateImageSize() {
[213] Fix | Delete
// Get the wrapper tag.
[214] Fix | Delete
const $wrapper = $( this ).closest( `.${ vars.classNames.settingsRow }` );
[215] Fix | Delete
// Get the selected value.
[216] Fix | Delete
const value = $( this ).val();
[217] Fix | Delete
[218] Fix | Delete
// Remove the previous image size class.
[219] Fix | Delete
$wrapper.removeClass( ( index, className ) => ( className.match( /has-image-size-\w+/g ) || [] ).join( ' ' ) );
[220] Fix | Delete
// Add the new image size class.
[221] Fix | Delete
$wrapper.addClass( `has-image-size-${ value }` );
[222] Fix | Delete
},
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Callback for the background color picker input change.
[226] Fix | Delete
*
[227] Fix | Delete
* @since 1.8.6
[228] Fix | Delete
*/
[229] Fix | Delete
handleOnChangeBackgroundColor() {
[230] Fix | Delete
const [ lightBackgroundColor, darkBackgroundColor ] = app.getBackgroundColors();
[231] Fix | Delete
[232] Fix | Delete
// Sync the background color value.
[233] Fix | Delete
app.syncBackgroundColors( lightBackgroundColor, darkBackgroundColor );
[234] Fix | Delete
},
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Callback for the body background and text color picker input changes.
[238] Fix | Delete
*
[239] Fix | Delete
* @since 1.8.6
[240] Fix | Delete
*/
[241] Fix | Delete
handleOnContrastChange() {
[242] Fix | Delete
// Bail if the color contrast checker is not available.
[243] Fix | Delete
if ( ! window.WPFormsColorContrastChecker ) {
[244] Fix | Delete
return;
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
// Define class names for elements.
[248] Fix | Delete
const { noticeWarning: noticeClassName, settingsRow: settingsRowClassName } = vars.classNames;
[249] Fix | Delete
[250] Fix | Delete
// Define color arrays for different elements.
[251] Fix | Delete
const textColors = [
[252] Fix | Delete
vars.cache.colors.light.text,
[253] Fix | Delete
vars.cache.colors.dark.text,
[254] Fix | Delete
];
[255] Fix | Delete
[256] Fix | Delete
textColors.forEach( ( textColor ) => {
[257] Fix | Delete
// Select color input elements.
[258] Fix | Delete
const $textColor = $( textColor );
[259] Fix | Delete
const $bodyColor = $textColor.parent().prev().prev().find( 'input' );
[260] Fix | Delete
[261] Fix | Delete
// Create a color contrast checker instance.
[262] Fix | Delete
const contrastChecker = new window.WPFormsColorContrastChecker( {
[263] Fix | Delete
textColor: $textColor.val(),
[264] Fix | Delete
bgColor: $bodyColor.val(),
[265] Fix | Delete
message: {
[266] Fix | Delete
contrastPass: '',
[267] Fix | Delete
contrastFail: l10n?.contrast_fail || '',
[268] Fix | Delete
},
[269] Fix | Delete
} );
[270] Fix | Delete
[271] Fix | Delete
// Check the color contrast.
[272] Fix | Delete
const contrastMessage = contrastChecker.checkContrast();
[273] Fix | Delete
[274] Fix | Delete
// Bail if there's no contrast message and the notice is not present.
[275] Fix | Delete
if ( ! contrastMessage ) {
[276] Fix | Delete
const $settingsRow = $textColor.closest( `.${ settingsRowClassName }` );
[277] Fix | Delete
$settingsRow.find( `.${ noticeClassName }` ).remove();
[278] Fix | Delete
return;
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
// Bail if the notice is already present.
[282] Fix | Delete
const $settingsRow = $textColor.closest( `.${ settingsRowClassName }` );
[283] Fix | Delete
if ( $settingsRow.find( `.${ noticeClassName }` ).length ) {
[284] Fix | Delete
return;
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
// Append contrast notice.
[288] Fix | Delete
$settingsRow.append( `<div class="${ noticeClassName }"><p>${ window.wp.escapeHtml.escapeHTML( contrastMessage ) }</p></div>` );
[289] Fix | Delete
} );
[290] Fix | Delete
},
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* Callback for input changes.
[294] Fix | Delete
* This method is used to update the preview URL.
[295] Fix | Delete
*
[296] Fix | Delete
* @since 1.8.6
[297] Fix | Delete
*/
[298] Fix | Delete
handleOnPreviewChanges() {
[299] Fix | Delete
// Bail if the XOR encryption is not available.
[300] Fix | Delete
if ( ! window.WPFormsXOR ) {
[301] Fix | Delete
return;
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
// Get the current input.
[305] Fix | Delete
const $this = $( this );
[306] Fix | Delete
[307] Fix | Delete
// Extract the 'name' attribute.
[308] Fix | Delete
const name = $this.attr( 'name' );
[309] Fix | Delete
[310] Fix | Delete
// Extract the ID from the 'name' attribute using a regex.
[311] Fix | Delete
// Explanation:
[312] Fix | Delete
// - /\[([^[\]]+)]/i: Match square brackets and capture the content inside.
[313] Fix | Delete
// - ( || [] )[1]: Use the captured content, or an empty array if not found.
[314] Fix | Delete
// - || name: If still not found, fallback to the original 'name'.
[315] Fix | Delete
// - replace(/-/g, '_'): Replace dashes with underscores in the ID.
[316] Fix | Delete
const id = ( ( name.match( /\[([^[\]]+)]/i ) || [] )[ 1 ] || name ).replace( /-/g, '_' );
[317] Fix | Delete
[318] Fix | Delete
// Get the current input value.
[319] Fix | Delete
const value = $this.val();
[320] Fix | Delete
[321] Fix | Delete
// Destructure utility functions from the wp.url object.
[322] Fix | Delete
const { isURL, addQueryArgs, getQueryArg } = wp.url;
[323] Fix | Delete
[324] Fix | Delete
// Query argument name.
[325] Fix | Delete
const queryArgName = 'wpforms_email_style_overrides';
[326] Fix | Delete
[327] Fix | Delete
// Create an XOR instance.
[328] Fix | Delete
const xorInstance = new window.WPFormsXOR();
[329] Fix | Delete
[330] Fix | Delete
// Filter and update the href attribute for elements with class 'wpforms-btn-preview'.
[331] Fix | Delete
$( '.wpforms-btn-preview' )
[332] Fix | Delete
.filter( ( index, elm ) => isURL( $( elm ).attr( 'href' ) ) )
[333] Fix | Delete
.attr( 'href', ( index, oldHref ) => {
[334] Fix | Delete
const existingOverrides = xorInstance.decrypt( getQueryArg( oldHref, queryArgName ) );
[335] Fix | Delete
const updatedOverrides = { ...existingOverrides, [ id ]: value };
[336] Fix | Delete
const updatedQueryString = xorInstance.encrypt( updatedOverrides );
[337] Fix | Delete
return addQueryArgs( oldHref, { [ queryArgName ]: updatedQueryString } );
[338] Fix | Delete
} );
[339] Fix | Delete
},
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Callback for the appearance mode toggle.
[343] Fix | Delete
*
[344] Fix | Delete
* @since 1.8.6
[345] Fix | Delete
*/
[346] Fix | Delete
handleOnAppearanceModeToggle() {
[347] Fix | Delete
// Reference to the clicked radio button.
[348] Fix | Delete
const $this = $( this );
[349] Fix | Delete
[350] Fix | Delete
// Define class names for elements.
[351] Fix | Delete
const { hide: hideClassName, settingField: settingFieldClassName } = vars.classNames;
[352] Fix | Delete
[353] Fix | Delete
// Get the value of the selected radio button.
[354] Fix | Delete
const selected = $this.val();
[355] Fix | Delete
[356] Fix | Delete
// Find the closest setting field container.
[357] Fix | Delete
const $settingField = $this.closest( `.${ settingFieldClassName }` );
[358] Fix | Delete
[359] Fix | Delete
// Find the unselected radio button within the same setting field.
[360] Fix | Delete
const $unselectedInput = $settingField.find( 'input:not(:checked)' );
[361] Fix | Delete
[362] Fix | Delete
// Get the value of the unselected radio button.
[363] Fix | Delete
const unselected = $unselectedInput.val();
[364] Fix | Delete
[365] Fix | Delete
$( `.email-${ selected }-mode` ).removeClass( hideClassName );
[366] Fix | Delete
$( `.email-${ unselected }-mode` ).addClass( hideClassName );
[367] Fix | Delete
},
[368] Fix | Delete
[369] Fix | Delete
/**
[370] Fix | Delete
* Relocate image size select input for styling purposes.
[371] Fix | Delete
*
[372] Fix | Delete
* @since 1.8.5
[373] Fix | Delete
*/
[374] Fix | Delete
relocateImageSize() {
[375] Fix | Delete
const $imgSize = $( '.wpforms-email-header-image-size' );
[376] Fix | Delete
[377] Fix | Delete
// Bail if there is no "Remove Image" button.
[378] Fix | Delete
if ( $imgSize.length === 0 ) {
[379] Fix | Delete
return;
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
$imgSize.each( ( index, elm ) => {
[383] Fix | Delete
const $this = $( elm );
[384] Fix | Delete
const $select = $this.find( 'select' );
[385] Fix | Delete
[386] Fix | Delete
// Bail if there is no select element.
[387] Fix | Delete
if ( $select.length === 0 ) {
[388] Fix | Delete
return;
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
// Get the header image element.
[392] Fix | Delete
const $headerImage = $this.prev();
[393] Fix | Delete
[394] Fix | Delete
// Move the select element before the "Remove Image" button.
[395] Fix | Delete
$headerImage.find( '.wpforms-setting-remove-image' ).before( $select.get( 0 ).outerHTML );
[396] Fix | Delete
[397] Fix | Delete
// Remove the original select element.
[398] Fix | Delete
$select.remove();
[399] Fix | Delete
[400] Fix | Delete
try {
[401] Fix | Delete
// Cache the new select input.
[402] Fix | Delete
const $newSelect = $headerImage.find( 'select' );
[403] Fix | Delete
// Add the image size class. Note that the default value is 140.
[404] Fix | Delete
$headerImage.addClass( `has-image-size-${ $newSelect.val() || 'medium' }` );
[405] Fix | Delete
// Bind the change event, and update the image size class.
[406] Fix | Delete
$newSelect.on( 'change', app.handleOnUpdateImageSize );
[407] Fix | Delete
// Initialize Choices.
[408] Fix | Delete
new Choices( $newSelect.get( 0 ), {
[409] Fix | Delete
searchEnabled: false,
[410] Fix | Delete
shouldSort: false,
[411] Fix | Delete
itemSelectText: '',
[412] Fix | Delete
} );
[413] Fix | Delete
[414] Fix | Delete
// Check if it's a legacy template and adjust settings accordingly.
[415] Fix | Delete
if ( app.isLegacyTemplate() ) {
[416] Fix | Delete
el.$wrapper.find( `.${ vars.classNames.noticeLegacy }` ).show();
[417] Fix | Delete
$headerImage.find( '.choices' ).hide();
[418] Fix | Delete
}
[419] Fix | Delete
} catch ( e ) {
[420] Fix | Delete
// Handle any potential errors, but continue execution.
[421] Fix | Delete
// eslint-disable-next-line no-console
[422] Fix | Delete
console.error( 'Error during relocation:', e );
[423] Fix | Delete
}
[424] Fix | Delete
} );
[425] Fix | Delete
},
[426] Fix | Delete
[427] Fix | Delete
/**
[428] Fix | Delete
* Determine whether the currently selected template is the "Legacy" template.
[429] Fix | Delete
* Legacy template is the one that its value is 'default'.
[430] Fix | Delete
*
[431] Fix | Delete
* @since 1.8.6
[432] Fix | Delete
*
[433] Fix | Delete
* @return {boolean} True if the current template is legacy.
[434] Fix | Delete
*/
[435] Fix | Delete
isLegacyTemplate() {
[436] Fix | Delete
return el.$wrapper.find( '.wpforms-setting-row-email_template input:checked' ).val() === 'default';
[437] Fix | Delete
},
[438] Fix | Delete
[439] Fix | Delete
/**
[440] Fix | Delete
* Get background colors for light and dark modes.
[441] Fix | Delete
*
[442] Fix | Delete
* This function retrieves the visible background color or falls back to the default one
[443] Fix | Delete
* for both light and dark modes.
[444] Fix | Delete
*
[445] Fix | Delete
* @since 1.8.6
[446] Fix | Delete
*
[447] Fix | Delete
* @return {Array} An array containing background colors for light and dark modes.
[448] Fix | Delete
*/
[449] Fix | Delete
getBackgroundColors() {
[450] Fix | Delete
// Get the visible background color or the default one.
[451] Fix | Delete
const getVisibleBackgroundColor = ( selector, fallbackSelector ) => {
[452] Fix | Delete
const visibleColor = el.$wrapper.find( `${ selector }:visible` ).val();
[453] Fix | Delete
return visibleColor || el.$wrapper.find( fallbackSelector ).val();
[454] Fix | Delete
};
[455] Fix | Delete
[456] Fix | Delete
// Return an array of background colors for light and dark modes.
[457] Fix | Delete
return [
[458] Fix | Delete
getVisibleBackgroundColor( ...vars.cache.colors.light.background ),
[459] Fix | Delete
getVisibleBackgroundColor( ...vars.cache.colors.dark.background ),
[460] Fix | Delete
];
[461] Fix | Delete
},
[462] Fix | Delete
[463] Fix | Delete
/**
[464] Fix | Delete
* Sync the background color value.
[465] Fix | Delete
*
[466] Fix | Delete
* @since 1.8.6
[467] Fix | Delete
*
[468] Fix | Delete
* @param {string} lightBackgroundColor The light background color in hex format.
[469] Fix | Delete
* @param {string} darkBackgroundColor The dark background color in hex format.
[470] Fix | Delete
*/
[471] Fix | Delete
syncBackgroundColors( lightBackgroundColor, darkBackgroundColor ) {
[472] Fix | Delete
// Bail if there is no light or dark background color.
[473] Fix | Delete
if ( ! lightBackgroundColor || ! darkBackgroundColor ) {
[474] Fix | Delete
return;
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
// Define color arrays for different elements.
[478] Fix | Delete
const backgrounds = [
[479] Fix | Delete
vars.cache.colors.light.background,
[480] Fix | Delete
vars.cache.colors.dark.background,
[481] Fix | Delete
];
[482] Fix | Delete
[483] Fix | Delete
// Reflect the change in the color picker.
[484] Fix | Delete
for ( let i = 0; i < backgrounds.length; i++ ) {
[485] Fix | Delete
// Determine the color based on the loop index.
[486] Fix | Delete
const color = i === 0 ? lightBackgroundColor : darkBackgroundColor;
[487] Fix | Delete
[488] Fix | Delete
// Select the corresponding image element based on the loop index.
[489] Fix | Delete
const $img = i === 0 ? $( '#wpforms-setting-row-email-header-image' ) : $( '#wpforms-setting-row-email-header-image-dark' );
[490] Fix | Delete
[491] Fix | Delete
// Iterate over elements in the current color array.
[492] Fix | Delete
backgrounds[ i ].forEach( ( selector ) => {
[493] Fix | Delete
// Find the element using the selector.
[494] Fix | Delete
const $background = el.$wrapper.find( selector );
[495] Fix | Delete
[496] Fix | Delete
// Set the color value for the element.
[497] Fix | Delete
$background.val( color );
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function