Skip to content

Commit e4fb28f

Browse files
committed
Avoid printing --dominant-color style when there is no dominant color
1 parent 6c3f1ae commit e4fb28f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

plugins/dominant-color-images/hooks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ function dominant_color_admin_script(): void {
221221
const tmpl = document.getElementById( 'tmpl-attachment' );
222222
if ( tmpl ) {
223223
tmpl.textContent = tmpl.textContent.replace( /^\s*<div[^>]*?(?=>)/, ( match ) => {
224-
let replaced = match.replace( /\sclass="/, " class=\"{{ data.hasTransparency ? \'has-transparency\' : \'not-transparent\' }} " );
224+
let replaced = match.replace( /\sclass="/, " class=\"{{ data.hasTransparency ? 'has-transparency' : 'not-transparent' }} " );
225225
replaced += ' data-dominant-color="{{ data.dominantColor }}"';
226226
replaced += ' data-has-transparency="{{ data.hasTransparency }}"';
227227
let hasStyleAttr = false;
228-
const colorStyle = '--dominant-color: #{{ data.dominantColor }};';
228+
const colorStyle = "{{ data.dominantColor ? '--dominant-color: #' + data.dominantColor + ';' : '' }}";
229229
replaced = replaced.replace( /\sstyle="/, ( styleMatch ) => {
230230
hasStyleAttr = true;
231231
return styleMatch + colorStyle;

0 commit comments

Comments
 (0)