2019-02-03 08:03:40 +01:00
|
|
|
<ModalDialog
|
|
|
|
{id}
|
|
|
|
{label}
|
|
|
|
background="var(--muted-modal-bg)"
|
|
|
|
muted="true"
|
|
|
|
className="media-modal-dialog"
|
|
|
|
>
|
|
|
|
<div class="media-container">
|
2019-02-10 03:06:58 +01:00
|
|
|
<ul class="media-scroll" ref:scroller>
|
2019-02-03 08:03:40 +01:00
|
|
|
{#each mediaItems as media}
|
2019-02-10 03:06:58 +01:00
|
|
|
<li class="media-scroll-item">
|
2019-02-03 08:03:40 +01:00
|
|
|
<div class="media-scroll-item-inner">
|
|
|
|
<div class="media-scroll-item-inner-inner">
|
2019-02-10 22:03:24 +01:00
|
|
|
{#if canPinchZoom && pinchZoomMode}
|
|
|
|
<PinchZoomable className='media-pinch-zoom' >
|
2019-02-07 06:00:30 +01:00
|
|
|
<MediaInDialog {media} />
|
|
|
|
</PinchZoomable>
|
|
|
|
{:else}
|
2019-02-03 21:33:15 +01:00
|
|
|
<MediaInDialog {media} />
|
2019-02-07 06:00:30 +01:00
|
|
|
{/if}
|
2019-02-03 08:03:40 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-02-10 03:06:58 +01:00
|
|
|
</li>
|
2019-02-03 08:03:40 +01:00
|
|
|
{/each}
|
2019-02-10 03:06:58 +01:00
|
|
|
</ul>
|
2019-02-03 21:33:15 +01:00
|
|
|
<div class="media-controls-outside">
|
2019-02-07 06:00:30 +01:00
|
|
|
{#if canPinchZoom}
|
|
|
|
<IconButton
|
|
|
|
className="media-control-button media-control-button-dummy-spacer"
|
|
|
|
href="#fa-search"
|
|
|
|
label=""
|
2019-02-10 04:05:59 +01:00
|
|
|
ariaHidden={true}
|
2019-02-07 06:00:30 +01:00
|
|
|
/>
|
|
|
|
{/if}
|
2019-02-03 21:33:15 +01:00
|
|
|
{#if dots.length > 1}
|
|
|
|
<div class="media-controls">
|
|
|
|
<IconButton
|
|
|
|
className="media-control-button"
|
|
|
|
disabled={scrolledItem === 0}
|
|
|
|
label="Show previous media"
|
|
|
|
href="#fa-angle-left"
|
|
|
|
on:click="prev()"
|
|
|
|
/>
|
|
|
|
{#each dots as dot, i (dot.i)}
|
|
|
|
<IconButton
|
|
|
|
className="media-control-button"
|
|
|
|
pressable={true}
|
|
|
|
label="Show {nth(i)} media"
|
|
|
|
pressed={i === scrolledItem}
|
|
|
|
href={i === scrolledItem ? '#fa-circle' : '#fa-circle-o'}
|
|
|
|
sameColorWhenPressed={true}
|
|
|
|
on:click="onClick(i)"
|
|
|
|
/>
|
|
|
|
{/each}
|
|
|
|
<IconButton
|
|
|
|
className="media-control-button"
|
|
|
|
disabled={scrolledItem === length - 1}
|
|
|
|
label="Show next media"
|
|
|
|
href="#fa-angle-right"
|
|
|
|
on:click="next()"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{/if}
|
2019-02-07 06:00:30 +01:00
|
|
|
{#if canPinchZoom}
|
|
|
|
<IconButton
|
|
|
|
className="media-control-button"
|
|
|
|
pressable={true}
|
|
|
|
pressed={pinchZoomMode}
|
|
|
|
label={pinchZoomMode ? 'Disable pinch-zoom mode' : 'Enable pinch-zoom mode'}
|
|
|
|
href="#fa-search"
|
|
|
|
on:click="togglePinchZoomMode()"
|
|
|
|
/>
|
|
|
|
{/if}
|
2019-02-03 21:33:15 +01:00
|
|
|
</div>
|
2019-02-03 08:03:40 +01:00
|
|
|
</div>
|
|
|
|
</ModalDialog>
|
2019-02-03 20:56:07 +01:00
|
|
|
|
|
|
|
<Shortcut scope='mediaDialog' key="ArrowLeft" on:pressed="prev()" />
|
|
|
|
<Shortcut scope='mediaDialog' key="ArrowRight" on:pressed="next()" />
|
2019-02-03 08:03:40 +01:00
|
|
|
<style>
|
|
|
|
:global(.media-modal-dialog) {
|
|
|
|
max-width: calc(100vw);
|
|
|
|
}
|
|
|
|
.media-container {
|
|
|
|
height: calc(100% - 64px); /* 44px X button height + 20px padding */
|
|
|
|
width: calc(100vw);
|
|
|
|
padding-top: 10px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
.media-scroll {
|
|
|
|
-webkit-overflow-scrolling: touch;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
overflow-x: auto;
|
|
|
|
width: 100%;
|
|
|
|
flex: 1;
|
|
|
|
scrollbar-width: none;
|
2019-02-09 21:01:29 +01:00
|
|
|
-ms-overflow-style: none;
|
2019-02-03 08:03:40 +01:00
|
|
|
}
|
|
|
|
|
2019-02-10 03:06:58 +01:00
|
|
|
ul.media-scroll {
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
list-style: none;
|
|
|
|
}
|
|
|
|
|
2019-02-03 08:03:40 +01:00
|
|
|
.media-scroll::-webkit-scrollbar {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.media-scroll-item {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
.media-scroll-item-inner {
|
|
|
|
width: 100vw;
|
|
|
|
height: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
.media-scroll-item-inner-inner {
|
|
|
|
height: calc(100% - 10px);
|
|
|
|
width: calc(100% - 10px);
|
|
|
|
padding: 5px;
|
|
|
|
}
|
|
|
|
|
2019-02-03 21:33:15 +01:00
|
|
|
.media-controls-outside {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
margin: 10px;
|
|
|
|
}
|
|
|
|
|
2019-02-03 08:03:40 +01:00
|
|
|
.media-controls {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
}
|
|
|
|
|
2019-02-03 21:33:15 +01:00
|
|
|
:global(.media-pinch-zoom) {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
:global(.media-control-button-dummy-spacer) {
|
|
|
|
visibility: hidden;
|
|
|
|
}
|
|
|
|
|
2019-02-10 00:25:30 +01:00
|
|
|
:global(.icon-button.media-control-button) {
|
|
|
|
margin: 0 5px;
|
2019-02-03 21:33:15 +01:00
|
|
|
}
|
|
|
|
|
2019-02-10 00:25:30 +01:00
|
|
|
@media (max-width: 767px) {
|
2019-02-03 21:33:15 +01:00
|
|
|
:global(.icon-button.media-control-button) {
|
2019-02-10 00:25:30 +01:00
|
|
|
margin: 0;
|
2019-02-03 21:33:15 +01:00
|
|
|
padding-left: 5px;
|
|
|
|
padding-right: 5px;
|
|
|
|
}
|
2019-02-03 08:03:40 +01:00
|
|
|
}
|
|
|
|
|
2019-02-10 00:25:30 +01:00
|
|
|
@media (max-width: 320px) {
|
|
|
|
:global(.icon-button.media-control-button) {
|
|
|
|
padding-left: 2px;
|
|
|
|
padding-right: 2px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-03 08:03:40 +01:00
|
|
|
@supports (scroll-snap-align: start) {
|
|
|
|
/* modern scroll snap points */
|
|
|
|
.media-scroll {
|
|
|
|
scroll-snap-type: x mandatory;
|
|
|
|
}
|
|
|
|
.media-scroll-item {
|
|
|
|
scroll-snap-align: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@supports not (scroll-snap-align: start) {
|
|
|
|
/* old scroll snap points spec */
|
|
|
|
.media-scroll {
|
|
|
|
-webkit-scroll-snap-type: mandatory;
|
|
|
|
scroll-snap-type: mandatory;
|
|
|
|
-webkit-scroll-snap-destination: 0% center;
|
|
|
|
scroll-snap-destination: 0% center;
|
|
|
|
-webkit-scroll-snap-points-x: repeat(100%);
|
|
|
|
scroll-snap-points-x: repeat(100%);
|
|
|
|
}
|
|
|
|
|
2019-02-09 23:31:49 +01:00
|
|
|
.media-scroll-item {
|
|
|
|
scroll-snap-coordinate: 0 0;
|
|
|
|
}
|
|
|
|
|
2019-02-03 08:03:40 +01:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import ModalDialog from './ModalDialog.html'
|
|
|
|
import MediaInDialog from './MediaInDialog.html'
|
|
|
|
import IconButton from '../../IconButton.html'
|
2019-02-03 20:56:07 +01:00
|
|
|
import Shortcut from '../../shortcut/Shortcut.html'
|
2019-02-03 21:33:15 +01:00
|
|
|
import PinchZoomable from './PinchZoomable.html'
|
2019-02-03 08:03:40 +01:00
|
|
|
import { show } from '../helpers/showDialog'
|
|
|
|
import { oncreate as onCreateDialog } from '../helpers/onCreateDialog'
|
|
|
|
import debounce from 'lodash-es/debounce'
|
|
|
|
import times from 'lodash-es/times'
|
2019-02-09 21:01:29 +01:00
|
|
|
import { smoothScroll, hasNativeSmoothScroll } from '../../../_utils/smoothScroll'
|
2019-02-03 08:03:40 +01:00
|
|
|
import { doubleRAF } from '../../../_utils/doubleRAF'
|
|
|
|
import { store } from '../../../_store/store'
|
2019-02-03 20:56:07 +01:00
|
|
|
import {
|
|
|
|
pushShortcutScope,
|
|
|
|
popShortcutScope } from '../../../_utils/shortcuts'
|
2019-02-03 08:03:40 +01:00
|
|
|
|
|
|
|
export default {
|
|
|
|
oncreate () {
|
|
|
|
onCreateDialog.call(this)
|
|
|
|
|
2019-02-05 18:54:38 +01:00
|
|
|
this.onScroll = debounce(this.onScroll.bind(this), 50, { leading: false, trailing: true })
|
2019-02-03 08:03:40 +01:00
|
|
|
|
|
|
|
let { scrolledItem } = this.get()
|
|
|
|
if (scrolledItem) {
|
|
|
|
doubleRAF(() => {
|
|
|
|
this.scrollToItem(scrolledItem, false)
|
|
|
|
this.setupScroll()
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setupScroll()
|
|
|
|
}
|
2019-02-03 20:56:07 +01:00
|
|
|
pushShortcutScope('mediaDialog')
|
2019-02-03 08:03:40 +01:00
|
|
|
},
|
|
|
|
ondestroy () {
|
|
|
|
this.teardownScroll()
|
2019-02-03 20:56:07 +01:00
|
|
|
popShortcutScope('mediaDialog')
|
2019-02-03 08:03:40 +01:00
|
|
|
},
|
|
|
|
store: () => store,
|
2019-02-03 21:33:15 +01:00
|
|
|
data: () => ({
|
|
|
|
pinchZoomMode: false
|
|
|
|
}),
|
2019-02-03 08:03:40 +01:00
|
|
|
computed: {
|
|
|
|
length: ({ mediaItems }) => mediaItems.length,
|
2019-02-07 06:00:30 +01:00
|
|
|
dots: ({ length }) => times(length, i => ({ i })),
|
|
|
|
canPinchZoom: ({ mediaItems }) => !mediaItems.some(media => media.type === 'video')
|
2019-02-03 08:03:40 +01:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
ModalDialog,
|
|
|
|
MediaInDialog,
|
2019-02-03 20:56:07 +01:00
|
|
|
IconButton,
|
2019-02-03 21:33:15 +01:00
|
|
|
Shortcut,
|
|
|
|
PinchZoomable
|
2019-02-03 08:03:40 +01:00
|
|
|
},
|
|
|
|
helpers: {
|
|
|
|
nth (i) {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
return 'first'
|
|
|
|
case 1:
|
|
|
|
return 'second'
|
|
|
|
case 2:
|
|
|
|
return 'third'
|
|
|
|
case 3:
|
|
|
|
return 'fourth'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
show,
|
|
|
|
setupScroll () {
|
|
|
|
this.refs.scroller.addEventListener('scroll', this.onScroll)
|
|
|
|
},
|
|
|
|
teardownScroll () {
|
|
|
|
this.refs.scroller.removeEventListener('scroll', this.onScroll)
|
|
|
|
},
|
|
|
|
onScroll () {
|
|
|
|
let { length } = this.get()
|
|
|
|
let { scrollWidth, scrollLeft } = this.refs.scroller
|
2019-02-03 20:10:58 +01:00
|
|
|
let scrolledItem = Math.round((scrollLeft / scrollWidth) * length)
|
2019-02-03 08:03:40 +01:00
|
|
|
this.set({ scrolledItem })
|
|
|
|
},
|
|
|
|
onClick (i) {
|
|
|
|
let { scrolledItem } = this.get()
|
|
|
|
if (scrolledItem !== i) {
|
|
|
|
this.scrollToItem(i, true)
|
|
|
|
}
|
|
|
|
},
|
2019-02-03 20:56:07 +01:00
|
|
|
next () {
|
|
|
|
let { scrolledItem, length } = this.get()
|
|
|
|
if (scrolledItem < length - 1) {
|
|
|
|
this.scrollToItem(scrolledItem + 1, true)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
prev () {
|
|
|
|
let { scrolledItem } = this.get()
|
|
|
|
if (scrolledItem > 0) {
|
|
|
|
this.scrollToItem(scrolledItem - 1, true)
|
|
|
|
}
|
|
|
|
},
|
2019-02-05 18:54:38 +01:00
|
|
|
scrollToItem (scrolledItem, smooth) {
|
|
|
|
this.set({ scrolledItem: scrolledItem })
|
2019-02-03 08:03:40 +01:00
|
|
|
let { length } = this.get()
|
|
|
|
let { scroller } = this.refs
|
|
|
|
let { scrollWidth } = scroller
|
2019-02-05 18:54:38 +01:00
|
|
|
let scrollLeft = Math.floor(scrollWidth * (scrolledItem / length))
|
2019-02-03 08:03:40 +01:00
|
|
|
if (smooth) {
|
2019-02-09 21:01:29 +01:00
|
|
|
if (!hasNativeSmoothScroll && 'StyleMedia' in window) {
|
|
|
|
// Edge has a weird bug where it changes the height if we try to
|
|
|
|
// smooth scroll, so disable smooth scrolling
|
|
|
|
scroller.scrollLeft = scrollLeft
|
|
|
|
} else {
|
|
|
|
smoothScroll(scroller, scrollLeft, true)
|
|
|
|
}
|
2019-02-03 08:03:40 +01:00
|
|
|
} else {
|
|
|
|
scroller.scrollLeft = scrollLeft
|
|
|
|
}
|
2019-02-03 21:33:15 +01:00
|
|
|
},
|
|
|
|
togglePinchZoomMode () {
|
|
|
|
this.set({ pinchZoomMode: !this.get().pinchZoomMode })
|
2019-02-03 08:03:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|