Skip to content

Commit 4a34e82

Browse files
wwalmnesGwenillia
andauthored
Fix/ji 6152 review adjustments (#235)
* JI-6152 fix bug with replicating button and fix minor styling issues * JI-6152 more styling adjustments * JI-6152 fix styling issues and focus * JI-6152 adjustments to badge * JI-6152 remove inline styling --------- Co-authored-by: Gwenillia <[email protected]>
1 parent 7d439f6 commit 4a34e82

6 files changed

+60
-18
lines changed

scripts/h5peditor-file-uploader.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ H5PEditor.FileUploader = (function ($, EventDispatcher) {
8484
/**
8585
* Open the file selector and trigger upload upon selecting file.
8686
*/
87-
self.openFileSelector = function () {
87+
self.openFileSelector = function ({ onChangeCallback } = {}) {
8888
// Create a file selector
8989
const input = document.createElement('input');
9090
input.type = 'file';
9191
input.setAttribute('accept', determineAllowedMimeTypes());
9292
input.style='display:none';
9393
input.addEventListener('change', function () {
94+
if (typeof onChangeCallback === 'function') {
95+
onChangeCallback();
96+
}
9497
// When files are selected, upload them
9598
self.uploadFiles(this.files);
9699
document.body.removeChild(input);

scripts/h5peditor-image.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ ns.widgets.image.prototype.appendTo = function ($wrapper) {
217217
if (this.boxEl.classList.contains('h5p-dnd__box--has-image')) {
218218
if ((e.code === 'Space' || e.code === 'Enter')) {
219219
this.isOriginalImage = true;
220-
this.openFileSelector();
220+
this.openFileSelector({
221+
onChangeCallback: () => {
222+
this.removeImage();
223+
}
224+
});
221225
}
222226
}
223227
});
@@ -231,7 +235,11 @@ ns.widgets.image.prototype.appendTo = function ($wrapper) {
231235
if (this.boxEl.classList.contains('h5p-dnd__box--has-image')
232236
&& e.target.closest('.h5p-dnd__img__container') === imageContainerEl) {
233237
this.isOriginalImage = true;
234-
this.openFileSelector();
238+
this.openFileSelector({
239+
onChangeCallback: () => {
240+
this.removeImage();
241+
}
242+
});
235243
}
236244
});
237245

@@ -352,14 +360,14 @@ ns.widgets.image.prototype.handleDragAndDrop = function (e) {
352360
ns.widgets.image.prototype.getBaseMarkup = function () {
353361
return `
354362
<div class="h5p-dnd__box__block"></div>
355-
<div class="h5p-dnd__column h5p-dnd__column--is-highlighted h5p-dnd__column--is-fixed h5p-dnd__column--hide-when-focus">
363+
<div class="h5p-dnd__column h5p-dnd__column--is-highlighted h5p-dnd__column--is-fixed h5p-dnd__column--hide-when-focus h5p-dnd__column--is-padded">
356364
<div class="h5p-dnd__upload-image-svg"></div>
357365
<button class="h5p-dnd__btn h5p-dnd__btn__upload" type="button">${ns.t('core', 'uploadImage')}</button>
358366
</div>
359367
360-
<div class="h5p-dnd__column h5p-dnd__column--hide-when-focus">
368+
<div class="h5p-dnd__column h5p-dnd__column--hide-when-focus h5p-dnd__column--is-padded">
361369
<div>
362-
${ns.t('core', 'dragAndDropAndPasteImage')} <span class="h5p-dnd__badge">ctrl&nbsp;(⌘)</span> + <span class="h5p-dnd__badge">v</span>
370+
${ns.t('core', 'dragAndDropAndPasteImage')} <span class="h5p-dnd__badge">ctrl<span class="h5p-dnd__badge__separator"></span>⌘</span> + <span class="h5p-dnd__badge">v</span>
363371
</div>
364372
<div class="h5p-errors"></div>
365373
</div>
@@ -402,7 +410,7 @@ ns.widgets.image.prototype.getUploadedMarkup = function () {
402410
<img class="h5p-dnd__img" src="${source}" alt="${altText}" />
403411
</div>
404412
</div>
405-
<div class="h5p-dnd__column h5p-dnd__column--show-when-focus">
413+
<div class="h5p-dnd__column h5p-dnd__column--show-when-focus h5p-dnd__column__drag-text">
406414
<div class="h5p-dnd__text">
407415
${ns.t('core', 'dragAndDropAndPasteReplaceImage')}
408416
</div>
@@ -472,6 +480,12 @@ ns.widgets.image.prototype.addFile = function () {
472480
actionsContainerEl.classList.add('h5p-image-action-container');
473481
actionsContainerEl.innerHTML = this.getImageActionMarkup();
474482

483+
const editBtnEl = actionsContainerEl.querySelector('.h5p-editing-image-button');
484+
// Need some time to change focus
485+
setTimeout(() => {
486+
editBtnEl.focus({focusVisible: true});
487+
}, 100);
488+
475489
this.boxContainerEl.insertBefore(actionsContainerEl, this.boxEl.nextElementSibling);
476490

477491
this.boxContainerEl.querySelector('.delete').addEventListener('click', (e) => {

styles/css/application.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

styles/scss/_form-field.scss

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
display: inline;
2121
}
2222

23-
.h5p-editor-image-buttons {
24-
float: left;
25-
clear: both;
26-
}
27-
2823
.library {
2924
border: 0;
3025
}

styles/scss/_h5peditor-drag-and-drop.scss

+32-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
flex-flow: row;
2121
align-items: stretch;
2222
justify-content: center;
23-
border: solid 2px #D0CFD4;
23+
border: solid 2px $dnd-gray-light;
2424
border-radius: 6px;
2525
flex: 1;
2626
min-height: 150px;
@@ -29,7 +29,7 @@
2929
}
3030

3131
.h5p-dnd__box--is-dashed {
32-
border: dashed 2px #D0CFD4;
32+
border: dashed 2px $dnd-gray-light;
3333
}
3434

3535
.h5p-dnd__box--is-inline {
@@ -39,14 +39,15 @@
3939
.h5p-dnd__box--has-image {
4040
flex-flow: column;
4141
width: min-content;
42+
min-height: auto;
4243
}
4344

4445
.h5p-dnd__box:focus-visible {
4546
outline: none;
4647
}
4748

4849
.h5p-dnd__box:not(.h5p-dnd__box--is-uploading):hover {
49-
border: dashed 2px #ACACAC;
50+
border: dashed 2px $dnd-gray-dark;
5051
}
5152

5253
.h5p-dnd__box--has-image:not(.h5p-dnd__box--is-uploading):hover,
@@ -104,6 +105,10 @@
104105
display: none;
105106
}
106107

108+
.h5p-dnd__column--is-padded {
109+
padding: 0 20px;
110+
}
111+
107112
.h5p-dnd__box--is-dragging .h5p-dnd__column--hide-when-focus {
108113
display: none;
109114
}
@@ -113,6 +118,10 @@
113118
display: flex;
114119
}
115120

121+
.h5p-dnd__column__drag-text {
122+
margin-top: -5px;
123+
}
124+
116125
.h5p-dnd__btn {
117126
display: flex;
118127
align-items: center;
@@ -139,6 +148,7 @@
139148
vertical-align: middle;
140149
font-size: 1.5em;
141150
line-height: 0.9;
151+
font-weight: 400;
142152
}
143153
}
144154

@@ -156,14 +166,32 @@
156166
background: #E7E9EE;
157167
color: #434446;
158168
text-transform: uppercase;
159-
font-weight: 700;
169+
font-weight: 400;
160170
font-size: 12px;
171+
font-family: 'Arial Black';
161172
border-radius: 6px;
162173
padding: 3px 8px;
174+
display: inline-flex;
175+
176+
.h5p-dnd__badge__separator {
177+
border-left: solid 2px rgba(67, 68, 70, 0.25);
178+
margin: 3px 6px;
179+
overflow: hidden;
180+
display: inline-block;
181+
overflow: hidden;
182+
top: 0;
183+
left: 0;
184+
right: 0;
185+
bottom: 0;
186+
position: relative;
187+
}
163188
}
164189

165190
.h5p-dnd__img {
166191
max-width: 175px;
192+
max-height: 120px;
193+
min-width: 40px;
194+
min-height: 40px;
167195
border-radius: 6px;
168196
display: block;
169197
}

styles/scss/_variables.scss

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ $form-label-importance-high: #356593;
5959
// Drag and drop
6060
$dnd-blue: #1670DF;
6161
$dnd-blue-faded: #f6faff;
62-
$dnd-text-color: #454347;
62+
$dnd-text-color: #454347;
63+
$dnd-gray-light: #D0CFD4;
64+
$dnd-gray-dark: #ACACAC;

0 commit comments

Comments
 (0)