Skip to content

Commit

Permalink
Show images in a modal
Browse files Browse the repository at this point in the history
  • Loading branch information
emptynick committed Sep 1, 2021
1 parent f91084e commit 4a26040
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Voyager documentation

This plugin for Voyager II allows you to browse the official documentation directly in your admin panel.

## TODO

- Parse alert blocks
- Display images in a lightbox
This plugin for Voyager II allows you to browse the official documentation directly in your admin panel.
2 changes: 1 addition & 1 deletion dist/voyager-docs.umd.js

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions src/components/Docs.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<Card :title="title">
<div class="w-full my-4 flex space-x-1">
<div class="w-full my-4 flex flex-wrap space-x-1 space-y-1">
<template v-for="(main, title) in toc">
<template v-if="title !== ''">
<Dropdown class="self-center" placement="bottom-start">
Expand Down Expand Up @@ -28,6 +28,9 @@
</div>
<div id="doc-content" v-html="parseContent(content, true)"></div>
</Card>
<Modal ref="imageModal">
<img :src="selectedImageSource" class="w-full">
</Modal>
</template>

<script>
Expand Down Expand Up @@ -103,7 +106,7 @@ export default {
if (!url.startsWith('https://') && !url.startsWith('http://')) {
url = url.replaceAll('../', '').replace('.gitbook/assets/', '');
return `src="${route('voyager.voyager-docs-asset')}?path=${url}" class="mx-auto py-2 w-full lg:w-4/6"`;
return `src="${route('voyager.voyager-docs-asset')}?path=${url}" class="mx-auto py-2 w-full lg:w-4/6 cursor-pointer"`;
}
return `src="${url}"`;
Expand Down Expand Up @@ -145,6 +148,22 @@ export default {
getLink(link) {
return `${this.route('voyager.voyager-docs')}?path=${link}`;
}
},
data() {
return {
selectedImageSource: null,
}
},
mounted() {
document.getElementById('doc-content').getElementsByTagName('img').forEach((image) => {
if (image.src.startsWith(`${route('voyager.voyager-docs-asset')}?path=`)) {
image.addEventListener('click', () => {
this.selectedImageSource = image.src;
this.$refs.imageModal.open();
});
}
});
}
}
</script>

0 comments on commit 4a26040

Please sign in to comment.