Show image description if present

Add a button to expand the image description if applicable
This commit is contained in:
Joel Bradshaw 2022-01-16 20:04:31 -08:00
parent 331f6e8803
commit ea1a7e3092
2 changed files with 50 additions and 4 deletions

View File

@ -255,6 +255,8 @@ export default {
showNextMedia: 'Show next media', showNextMedia: 'Show next media',
enterPinchZoom: 'Pinch-zoom mode', enterPinchZoom: 'Pinch-zoom mode',
exitPinchZoom: 'Exit pinch-zoom mode', exitPinchZoom: 'Exit pinch-zoom mode',
showFullImageDescription: 'Show full image description',
hideFullImageDescription: 'Hide full image description',
showMedia: `Show {index, select, showMedia: `Show {index, select,
1 {first} 1 {first}
2 {second} 2 {second}

View File

@ -25,8 +25,24 @@
</li> </li>
{/each} {/each}
</ul> </ul>
{#if hasDescription }
<div class="media-description-outside {showFullImageDescription ? 'expanded' : ''}">
{mediaItem.description}
</div>
{/if}
<div class="media-controls-outside" on:click="onMediaControlsClick(event)"> <div class="media-controls-outside" on:click="onMediaControlsClick(event)">
{#if canPinchZoom} {#if hasDescription }
<IconButton
className="media-control-button"
svgClassName="media-control-button-svg"
pressable={hasDescription}
pressed={showFullImageDescription}
pressedLabel="{intl.hideFullImageDescription}"
href="#fa-info-circle"
label="{intl.showFullImageDescription}"
on:click="toggleFullImageDescription()"
/>
{:elseif canPinchZoom }
<IconButton <IconButton
className="media-control-button media-control-button-dummy-spacer" className="media-control-button media-control-button-dummy-spacer"
svgClassName="media-control-button-svg" svgClassName="media-control-button-svg"
@ -77,16 +93,25 @@
</li> </li>
</ul> </ul>
{/if} {/if}
{#if canPinchZoom} {#if canPinchZoom }
<IconButton <IconButton
className="media-control-button" className="media-control-button"
svgClassName="media-control-button-svg" svgClassName="media-control-button-svg"
pressable={true} pressable={canPinchZoom}
pressed={pinchZoomMode} pressed={pinchZoomMode}
label="{intl.enterPinchZoom}" label="{intl.enterPinchZoom}"
pressedLabel="{intl.exitPinchZoom}" pressedLabel="{intl.exitPinchZoom}"
href="#fa-search" href="#fa-search"
on:click="togglePinchZoomMode()" on:click="togglePinchZoomMode()"
ariaHidden={!canPinchZoom}
/>
{:elseif hasDescription }
<IconButton
className="media-control-button media-control-button-dummy-spacer"
svgClassName="media-control-button-svg"
href="#fa-search"
label=""
ariaHidden={true}
/> />
{/if} {/if}
</div> </div>
@ -142,6 +167,20 @@
padding: 15px 5px 5px 5px; padding: 15px 5px 5px 5px;
} }
.media-description-outside {
margin: 5px 15px;
max-height: 1.5em;
text-align: center;
color: white;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.media-description-outside.expanded {
max-height: none;
white-space: normal;
}
.media-controls-outside { .media-controls-outside {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@ -263,12 +302,14 @@
}, },
store: () => store, store: () => store,
data: () => ({ data: () => ({
pinchZoomMode: false pinchZoomMode: false,
showFullImageDescription: false
}), }),
computed: { computed: {
length: ({ mediaItems }) => mediaItems.length, length: ({ mediaItems }) => mediaItems.length,
dots: ({ length }) => times(length, i => ({ i })), dots: ({ length }) => times(length, i => ({ i })),
canPinchZoom: ({ mediaItems }) => !mediaItems.some(media => ['video', 'audio'].includes(media.type)), canPinchZoom: ({ mediaItems }) => !mediaItems.some(media => ['video', 'audio'].includes(media.type)),
hasDescription: ({ mediaItem }) => mediaItem.description,
mediaItem: ({ mediaItems, scrolledItem }) => mediaItems[scrolledItem], mediaItem: ({ mediaItems, scrolledItem }) => mediaItems[scrolledItem],
nativeWidth: ({ mediaItem }) => get(mediaItem, ['meta', 'original', 'width'], 300), // TODO: Pleroma placeholder nativeWidth: ({ mediaItem }) => get(mediaItem, ['meta', 'original', 'width'], 300), // TODO: Pleroma placeholder
nativeHeight: ({ mediaItem }) => get(mediaItem, ['meta', 'original', 'height'], 200) // TODO: Pleroma placeholder nativeHeight: ({ mediaItem }) => get(mediaItem, ['meta', 'original', 'height'], 200) // TODO: Pleroma placeholder
@ -355,6 +396,9 @@
togglePinchZoomMode () { togglePinchZoomMode () {
this.set({ pinchZoomMode: !this.get().pinchZoomMode }) this.set({ pinchZoomMode: !this.get().pinchZoomMode })
}, },
toggleFullImageDescription () {
this.set({ showFullImageDescription: !this.get().showFullImageDescription })
},
onImageClick (e) { onImageClick (e) {
const { nativeWidth, nativeHeight, pinchZoomMode } = this.get() const { nativeWidth, nativeHeight, pinchZoomMode } = this.get()
if (pinchZoomMode) { if (pinchZoomMode) {