Skip to content

Commit 37ba28e

Browse files
committed
Improve the preview
1 parent 5b44c98 commit 37ba28e

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

css/cloudinary.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/asset-edit.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/components/_edit_overlay.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,9 @@
8686
padding: 7px 14px;
8787
}
8888
}
89+
90+
.cld-ui-suffix {
91+
margin-left: 0;
92+
}
8993
}
9094

src/js/asset-edit.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,15 @@ const AssetEdit = {
129129
// Add event listeners with appropriate logic for each overlay type
130130
secondaryTextInputs.forEach(({ input, event }) => {
131131
if (input) {
132-
input.addEventListener(event, updatePreviewForTextOverlay);
132+
// Special handling for color input to ensure value is updated
133+
if (input === this.textOverlayColorInput) {
134+
input.addEventListener(event, () => {
135+
// Use setTimeout to ensure the input value has been updated
136+
setTimeout(updatePreviewForTextOverlay, 0);
137+
});
138+
} else {
139+
input.addEventListener(event, updatePreviewForTextOverlay);
140+
}
133141
}
134142
});
135143

@@ -175,7 +183,20 @@ const AssetEdit = {
175183
return;
176184
}
177185

178-
gridOptions.forEach( ( option, index ) => {
186+
const overlayConfig = {
187+
'edit-overlay-grid-text': {
188+
positionInput: this.textOverlayPositionInput,
189+
contentInput: this.textOverlayTextInput
190+
},
191+
'edit-overlay-grid-image': {
192+
positionInput: this.imageOverlayPositionInput,
193+
contentInput: this.imageOverlayImageIdInput
194+
}
195+
};
196+
197+
const config = overlayConfig[gridId];
198+
199+
gridOptions.forEach( ( option ) => {
179200
const cell = document.createElement( 'div' );
180201
cell.className = 'edit-overlay-grid__cell';
181202
cell.dataset.gravity = option;
@@ -184,20 +205,12 @@ const AssetEdit = {
184205
grid.querySelectorAll( '.edit-overlay-grid__cell--selected' ).forEach( c => c.classList.remove( 'edit-overlay-grid__cell--selected' ) );
185206
cell.classList.add( 'edit-overlay-grid__cell--selected' );
186207

187-
if (gridId === 'edit-overlay-grid-text') {
188-
this.textOverlayPositionInput.value = option;
208+
if (config) {
209+
config.positionInput.value = option;
189210

190-
// Update preview only if we have text content
191-
const hasText = this.textOverlayTextInput?.value?.trim();
192-
if (hasText) {
193-
this.preview.setSrc( this.getSrc() );
194-
}
195-
} else if (gridId === 'edit-overlay-grid-image') {
196-
this.imageOverlayPositionInput.value = option;
211+
const hasContent = config.contentInput?.value?.trim();
197212

198-
// Update preview only if we have image ID
199-
const hasImageId = this.imageOverlayImageIdInput?.value?.trim();
200-
if (hasImageId) {
213+
if (hasContent) {
201214
this.preview.setSrc( this.getSrc() );
202215
}
203216
}

ui-definitions/settings-pages.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,11 @@
651651
'title' => __( 'Font Face', 'cloudinary' ),
652652
'default' => 'Arial',
653653
'options' => array(
654-
'Arial' => __( 'Arial', 'cloudinary' ),
655-
'Verdana' => __( 'Verdana', 'cloudinary' ),
656-
'Tahoma' => __( 'Tahoma', 'cloudinary' ),
657-
'Georgia' => __( 'Georgia', 'cloudinary' ),
658-
'Garamond' => __( 'Garamond', 'cloudinary' ),
654+
'Arial' => __( 'Arial (sans-serif)', 'cloudinary' ),
655+
'Verdana' => __( 'Verdana (sans-serif)', 'cloudinary' ),
656+
'Times New Roman' => __( 'Times New Roman (serif)', 'cloudinary' ),
657+
'Courier New' => __( 'Courier New (monospace)', 'cloudinary' ),
658+
'Georgia' => __( 'Georgia (serif)', 'cloudinary' ),
659659
),
660660
),
661661
),
@@ -886,14 +886,14 @@
886886
array(
887887
'type' => 'number',
888888
'title' => __( 'X Offset', 'cloudinary' ),
889-
'default' => '',
889+
'default' => 0,
890890
'slug' => 'image_overlay_x_offset',
891891
'suffix' => 'px',
892892
),
893893
array(
894894
'type' => 'number',
895895
'title' => __( 'Y Offset', 'cloudinary' ),
896-
'default' => '',
896+
'default' => 0,
897897
'slug' => 'image_overlay_y_offset',
898898
'suffix' => 'px',
899899
),

0 commit comments

Comments
 (0)