Improvement: Add Upload Button to Image Gallery (#4500) * Improvement: Add Upload Button to Image Gallery - Added an **Upload Image** button to the **Image Gallery** for a more intuitive experience and easier use on mobile devices ~~(so I can upload some awesome GIFs right from my phone)~~ - Adjusted the `<select class="gallery-sort-select">` menu styling for better consistency with other sections, making it more compact and reducing wasted space * Fix type error --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Signed| @@ -63,10 +63,10 @@ mutationObserver.observe(document.body, { | ||
| 63 | 63 | }); |
| 64 | 64 | |
| 65 | 65 | const SORT = Object.freeze({ |
| 66 | 66 | NAME_ASC: { value: 'nameAsc', field: 'name', order: 'asc', label: t`Sort By: Name (A-Z)` }, |
| 67 | 67 | NAME_DESC: { value: 'nameDesc', field: 'name', order: 'desc', label: t`Sort By: Name (Z-A)` }, |
| 68 | 68 | DATE_ASCDATE_DESC: { value: 'dateAscdateDesc', field: 'date', order: 'ascdesc', label: t`Sort By: Date (Oldest First)Newest` }, |
| 69 | 69 | DATE_DESCDATE_ASC: { value: 'dateDescdateAsc', field: 'date', order: 'descasc', label: t`Sort By: Date (Newest First)Oldest` }, |
| 70 | 70 | }); |
| 71 | 71 | |
| 72 | 72 | const defaultSettings = Object.freeze({ |
| @@ -376,6 +376,11 @@ async function makeMovable(url) { | ||
| 376 | 376 | const titleText = document.createElement('span'); |
| 377 | 377 | titleText.textContent = t`Image Gallery`; |
| 378 | 378 | dragTitle.append(titleText); |
| 379 | + | |
| 380 | + // Create a container for the controls | |
| 381 | + const controlsContainer = document.createElement('div'); | |
| 382 | + controlsContainer.classList.add('flex-container', 'alignItemsCenter'); | |
| 383 | + | |
| 379 | 384 | const sortSelect = document.createElement('select'); |
| 380 | 385 | sortSelect.classList.add('gallery-sort-select'); |
| 381 | 386 | |
| @@ -394,7 +399,42 @@ async function makeMovable(url) { | ||
| 394 | 399 | }); |
| 395 | 400 | |
| 396 | 401 | sortSelect.value = getSortOrder(); |
| 397 | 402 | dragTitlecontrolsContainer.appendappendChild(sortSelect); |
| 403 | + | |
| 404 | + // Create the "Add Image" button | |
| 405 | + const addImageButton = document.createElement('div'); | |
| 406 | + addImageButton.classList.add('menu_button', 'menu_button_icon', 'interactable'); | |
| 407 | + addImageButton.title = 'Add Image'; | |
| 408 | + addImageButton.innerHTML = '<i class="fa-solid fa-plus fa-fw"></i><div>Add Image</div>'; | |
| 409 | + | |
| 410 | + // Create a hidden file input | |
| 411 | + const fileInput = document.createElement('input'); | |
| 412 | + fileInput.type = 'file'; | |
| 413 | + fileInput.accept = 'image/*'; | |
| 414 | + fileInput.multiple = true; | |
| 415 | + fileInput.style.display = 'none'; | |
| 416 | + | |
| 417 | + // Trigger file input when the button is clicked | |
| 418 | + addImageButton.addEventListener('click', () => { | |
| 419 | + fileInput.click(); | |
| 420 | + }); | |
| 421 | + | |
| 422 | + // Handle file selection | |
| 423 | + fileInput.addEventListener('change', async () => { | |
| 424 | + const files = fileInput.files; | |
| 425 | + if (files.length > 0) { | |
| 426 | + for (const file of files) { | |
| 427 | + await uploadFile(file, url); | |
| 428 | + } | |
| 429 | + // Refresh the gallery | |
| 430 | + closeButton.trigger('click'); | |
| 431 | + await showCharGallery(); | |
| 432 | + } | |
| 433 | + }); | |
| 434 | + | |
| 435 | + controlsContainer.appendChild(addImageButton); | |
| 436 | + dragTitle.append(controlsContainer); | |
| 437 | + newElement.append(fileInput); // Append hidden file input to the main element | |
| 398 | 438 | |
| 399 | 439 | // add no-scrollbar class to this element |
| 400 | 440 | newElement.addClass('no-scrollbar'); |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | display: flex; |
| 3 | 3 | align-items: center; |
| 4 | 4 | justify-content: center; |
| 5 | + gap: 4px; | |
| 5 | 6 | } |
| 6 | 7 | |
| 7 | 8 | .gallery-folder-input { |
| @@ -26,13 +27,13 @@ | ||
| 26 | 27 | text-overflow: ellipsis; |
| 27 | 28 | width: 100%; |
| 28 | 29 | opacity: 0.8; |
| 29 | 30 | background-color: nonevar(--black30a); |
| 31 | + border: 1px solid var(--SmartThemeBorderColor); | |
| 30 | 32 | background-image: url(/img/down-arrow.svg); |
| 31 | 33 | background-repeat: no-repeat; |
| 32 | 34 | background-position: right 6px center; |
| 33 | 35 | background-size: 8px 5px; |
| 34 | 36 | padding-right: 20px; |
| 35 | - font-size: calc(var(--mainFontSize)* 0.9); | |
| 36 | 37 | margin-bottom: 0; |
| 37 | 38 | } |
| 38 | 39 | |