Implement image dialog
This commit is contained in:
		
							
								
								
									
										54
									
								
								src/client/components/image-viewer.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/client/components/image-viewer.vue
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| <template> | ||||
| <x-modal ref="modal" @closed="() => { $emit('closed'); destroyDom(); }"> | ||||
| 	<img class="xubzgfga" ref="img" :src="image.url" :alt="image.name" :title="image.name" @click="close" tabindex="-1"/> | ||||
| </x-modal> | ||||
| </template> | ||||
|  | ||||
| <script lang="ts"> | ||||
| import Vue from 'vue'; | ||||
| import i18n from '../i18n'; | ||||
| import XModal from './modal.vue'; | ||||
|  | ||||
| export default Vue.extend({ | ||||
| 	i18n, | ||||
|  | ||||
| 	components: { | ||||
| 		XModal, | ||||
| 	}, | ||||
|  | ||||
| 	props: { | ||||
| 		image: { | ||||
| 			type: Object, | ||||
| 			required: true | ||||
| 		}, | ||||
| 	}, | ||||
|  | ||||
| 	mounted() { | ||||
| 		this.$nextTick(() => { | ||||
| 			this.$refs.img.focus(); | ||||
| 		}); | ||||
| 	}, | ||||
|  | ||||
| 	methods: { | ||||
| 		close() { | ||||
| 			this.$refs.modal.close(); | ||||
| 		}, | ||||
| 	} | ||||
| }); | ||||
| </script> | ||||
|  | ||||
| <style lang="scss" scoped> | ||||
| .xubzgfga { | ||||
| 	position: fixed; | ||||
| 	z-index: 2; | ||||
| 	top: 0; | ||||
| 	right: 0; | ||||
| 	bottom: 0; | ||||
| 	left: 0; | ||||
| 	max-width: 100%; | ||||
| 	max-height: 100%; | ||||
| 	margin: auto; | ||||
| 	cursor: zoom-out; | ||||
| 	image-orientation: from-image; | ||||
| } | ||||
| </style> | ||||
| @@ -20,6 +20,7 @@ import Vue from 'vue'; | ||||
| import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons'; | ||||
| import i18n from '../i18n'; | ||||
| import { getStaticImageUrl } from '../scripts/get-static-image-url'; | ||||
| import ImageViewer from './image-viewer.vue'; | ||||
|  | ||||
| export default Vue.extend({ | ||||
| 	i18n, | ||||
| @@ -60,7 +61,16 @@ export default Vue.extend({ | ||||
| 	}, | ||||
| 	methods: { | ||||
| 		onClick() { | ||||
| 			window.open(this.image.url, '_blank'); | ||||
| 			if (this.$store.state.device.imageNewTab) { | ||||
| 				window.open(this.image.url, '_blank'); | ||||
| 			} else { | ||||
| 				const viewer = this.$root.new(ImageViewer, { | ||||
| 					image: this.image | ||||
| 				}); | ||||
| 				this.$once('hook:beforeDestroy', () => { | ||||
| 					viewer.close(); | ||||
| 				}); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| }); | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| <template> | ||||
| <div class="mk-modal"> | ||||
| <div class="mk-modal" v-hotkey.global="keymap"> | ||||
| 	<transition :name="$store.state.device.animation ? 'bg-fade' : ''" appear> | ||||
| 		<div class="bg" ref="bg" v-if="show" @click="close()"></div> | ||||
| 	</transition> | ||||
| @@ -20,6 +20,13 @@ export default Vue.extend({ | ||||
| 			show: true, | ||||
| 		}; | ||||
| 	}, | ||||
| 	computed: { | ||||
| 		keymap(): any { | ||||
| 			return { | ||||
| 				'esc': this.close, | ||||
| 			}; | ||||
| 		}, | ||||
| 	}, | ||||
| 	methods: { | ||||
| 		close() { | ||||
| 			this.show = false; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo