Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29267,6 +29267,7 @@ class FullImageModal {
this.objectUrl = null;
this.requestId = 0;
this.abortController = null;
this.rotationDegrees = 0;
this.scale = 1;
this.translateX = 0;
this.translateY = 0;
Expand All @@ -29279,6 +29280,7 @@ class FullImageModal {
this.modal = document.getElementById('fullImageModal');
this.header = this.modal.querySelector('.modal-header');
this.closeButton = document.getElementById('closeFullImageModal');
this.rotateButton = document.getElementById('fullImageRotate');
this.title = document.getElementById('fullImageModalTitle');
this.viewer = document.getElementById('fullImageViewer');
this.loading = document.getElementById('fullImageLoading');
Expand All @@ -29290,12 +29292,13 @@ class FullImageModal {
this.zoomInButton = document.getElementById('fullImageZoomIn');
this.zoomOutButton = document.getElementById('fullImageZoomOut');

assert(this.modal && this.header && this.closeButton && this.title && this.viewer && this.loading && this.loadingText
&& this.error && this.image && this.video
assert(this.modal && this.header && this.closeButton && this.rotateButton && this.title
&& this.viewer && this.loading && this.loadingText && this.error && this.image && this.video
&& this.zoomControls && this.zoomInButton && this.zoomOutButton,
'Media modal elements are required');

this.closeButton.addEventListener('click', () => this.close());
this.rotateButton.addEventListener('click', () => this.rotateMedia());
this.zoomInButton.addEventListener('click', () => this.zoomBy(0.5));
this.zoomOutButton.addEventListener('click', () => this.zoomBy(-0.5));
this.viewer.addEventListener('touchstart', (event) => this.handleTouchStart(event), { passive: false });
Expand Down Expand Up @@ -29387,6 +29390,7 @@ class FullImageModal {
if (!this.isCurrentRequest(requestId) || this.objectUrl !== objectUrl) return;
this.loading.hidden = true;
this.image.hidden = false;
this.rotateButton.hidden = false;
this.viewer.setAttribute('aria-busy', 'false');
this.updateZoomControls();
this.revealChrome();
Expand All @@ -29403,6 +29407,7 @@ class FullImageModal {
this.video.onloadedmetadata = () => {
if (!this.isCurrentRequest(requestId)) return;
this.loading.hidden = true;
this.rotateButton.hidden = false;
this.viewer.setAttribute('aria-busy', 'false');
this.revealChrome();
};
Expand Down Expand Up @@ -29540,17 +29545,20 @@ class FullImageModal {
}

constrainTranslation() {
const maxX = Math.max(0, (this.image.clientWidth * this.scale - this.viewer.clientWidth) / 2);
const maxY = Math.max(0, (this.image.clientHeight * this.scale - this.viewer.clientHeight) / 2);
const sideways = this.rotationDegrees % 180 !== 0;
const width = sideways ? this.image.clientHeight : this.image.clientWidth;
const height = sideways ? this.image.clientWidth : this.image.clientHeight;
const maxX = Math.max(0, (width * this.scale - this.viewer.clientWidth) / 2);
const maxY = Math.max(0, (height * this.scale - this.viewer.clientHeight) / 2);
this.translateX = Math.min(maxX, Math.max(-maxX, this.translateX));
this.translateY = Math.min(maxY, Math.max(-maxY, this.translateY));
}

applyTransform() {
this.image.style.transform = this.scale === 1
? ''
: `translate3d(${this.translateX}px, ${this.translateY}px, 0) scale(${this.scale})`;
this.viewer.classList.toggle('is-zoomed', this.scale > 1);
const zoomed = this.scale > 1;
this.image.style.translate = zoomed ? `${this.translateX}px ${this.translateY}px` : '';
this.image.style.scale = zoomed ? this.scale : '';
this.viewer.classList.toggle('is-zoomed', zoomed);
this.updateZoomControls();
}

Expand All @@ -29575,14 +29583,28 @@ class FullImageModal {
this.zoomOutButton.disabled = imageUnavailable || this.scale <= 1;
}

resetTransform() {
rotateMedia() {
if (this.rotateButton.hidden) return;

this.setRotation((this.rotationDegrees + 90) % 360);
this.resetZoom();
}

setRotation(degrees) {
this.rotationDegrees = degrees;
this.viewer.style.setProperty('--media-rotation', `${degrees}deg`);
this.viewer.classList.toggle('is-rotated', degrees !== 0);
this.viewer.classList.toggle('is-sideways', degrees % 180 !== 0);
}

resetZoom() {
this.scale = 1;
this.translateX = 0;
this.translateY = 0;
this.touchGesture = null;
this.dragPointerId = null;
if (this.image) this.image.style.transform = '';
this.viewer?.classList.remove('is-zoomed', 'is-dragging');
this.viewer.classList.remove('is-dragging');
this.applyTransform();
}

clearMedia() {
Expand All @@ -29600,7 +29622,6 @@ class FullImageModal {
this.video.removeAttribute('poster');
this.video.load();
this.video.hidden = true;
this.resetTransform();
this.image.onload = null;
this.image.onerror = null;
this.image.removeAttribute('src');
Expand All @@ -29609,7 +29630,9 @@ class FullImageModal {
this.error.hidden = true;
this.viewer.setAttribute('aria-busy', 'false');
this.image.alt = '';
this.updateZoomControls();
this.rotateButton.hidden = true;
this.setRotation(0);
this.resetZoom();

if (this.objectUrl) {
URL.revokeObjectURL(this.objectUrl);
Expand Down
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,11 @@ <h3 id="locationShareTitle">Share Location</h3>
<div class="modal-header">
<button class="back-button" id="closeFullImageModal" type="button" aria-label="Close media"></button>
<div class="modal-title" id="fullImageModalTitle">Media</div>
<button class="full-image-rotate-button" id="fullImageRotate" type="button" aria-label="Rotate clockwise" title="Rotate clockwise" hidden>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M20 4v5h-5M20 9a8 8 0 1 0 0 6" />
</svg>
</button>
</div>
<div class="modal-content full-image-modal-content">
<div class="full-image-viewer" id="fullImageViewer" aria-busy="false">
Expand Down
45 changes: 42 additions & 3 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1801,9 +1801,9 @@ button:disabled {
pointer-events: none;
}

.full-image-modal .back-button {
.full-image-modal .back-button,
.full-image-rotate-button {
top: calc(12px + env(safe-area-inset-top, 0px));
left: calc(12px + env(safe-area-inset-left, 0px));
width: 44px;
height: 44px;
padding: 10px;
Expand All @@ -1812,11 +1812,29 @@ button:disabled {
pointer-events: auto;
}

.full-image-modal .back-button {
left: calc(12px + env(safe-area-inset-left, 0px));
}

.full-image-rotate-button {
position: absolute;
right: calc(12px + env(safe-area-inset-right, 0px));
border: 0;
background: none;
cursor: pointer;
touch-action: manipulation;
}

.full-image-rotate-button svg {
display: block;
}

.full-image-modal .back-button::before {
filter: brightness(0) invert(1);
}

.full-image-modal .back-button:focus-visible {
.full-image-modal .back-button:focus-visible,
.full-image-rotate-button:focus-visible {
outline: 2px solid #fff;
outline-offset: 2px;
}
Expand All @@ -1838,6 +1856,7 @@ button:disabled {
position: relative;
width: 100%;
height: 100%;
container-type: size;
display: flex;
align-items: center;
justify-content: center;
Expand All @@ -1851,13 +1870,20 @@ button:disabled {
width: auto;
height: auto;
object-fit: contain;
rotate: var(--media-rotation, 0deg);
transform-origin: center;
user-select: none;
-webkit-user-drag: none;
-webkit-touch-callout: none;
will-change: transform;
}

.full-image-viewer.is-sideways .full-image-viewer-image {
flex-shrink: 0;
max-width: 100cqh;
max-height: 100cqw;
}

.full-image-modal.is-video,
.full-image-modal.is-video .full-image-modal-content {
touch-action: auto;
Expand All @@ -1870,6 +1896,19 @@ button:disabled {
background: #000;
}

.full-image-viewer.is-rotated .full-image-viewer-video:not(:fullscreen) {
/* Leave room at both ends so the overlay header can't cover rotated video controls. */
--rotated-video-height: calc(100cqh - 2 * (64px + env(safe-area-inset-top, 0px)));
height: var(--rotated-video-height);
rotate: var(--media-rotation);
}

.full-image-viewer.is-sideways .full-image-viewer-video:not(:fullscreen) {
flex-shrink: 0;
width: var(--rotated-video-height);
height: 100cqw;
}

.full-image-modal.is-video .full-image-loading {
position: absolute;
z-index: 1;
Expand Down
Loading