Skip to content

Commit 9d89c44

Browse files
pbearnewestonruter
andauthored
Update plugins/dominant-color-images/hooks.php
Co-authored-by: Weston Ruter <[email protected]>
1 parent 89c62b3 commit 9d89c44

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

plugins/dominant-color-images/hooks.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,13 @@ function dominant_color_admin_script(): void {
221221
<script type="module">
222222
const tmpl = document.getElementById( 'tmpl-attachment' );
223223
if ( tmpl ) {
224-
tmpl.textContent = tmpl.textContent.replace(
225-
'{{ data.orientation }}"',
226-
'{{ data.orientation }} {{ data.hasTransparency ? \'has-transparency\' : \'not-transparent\' }}" data-dominant-color="{{ data.dominantColor }}" data-has-transparency="{{ data.hasTransparency }}" style="--dominant-color: #{{ data.dominantColor }};"'
227-
);
224+
tmpl.textContent = tmpl.textContent.replace( /^\s*<div[^>]*?(?=>)/, ( match ) => {
225+
let replaced = match.replace( /\sclass="/, " class=\"{{ data.hasTransparency ? \'has-transparency\' : \'not-transparent\' }} " );
226+
replaced += ' data-dominant-color="{{ data.dominantColor }}"';
227+
replaced += ' data-has-transparency="{{ data.hasTransparency }}"';
228+
replaced += ' style="--dominant-color: #{{ data.dominantColor }};"'; // TODO: Potentially there could be a style attribute as well!
229+
return replaced;
230+
} );
228231
}
229232
</script>
230233
<?php

0 commit comments

Comments
 (0)