show embed dialog

This commit is contained in:
ThatOneCalculator 2023-07-03 00:48:06 -07:00
parent f10bc5488d
commit b02bb19b7b
No known key found for this signature in database
GPG key ID: 8703CACD01000000
5 changed files with 111 additions and 1 deletions

View file

@ -1114,6 +1114,8 @@ isPatron: "Calckey Patron"
reactionPickerSkinTone: "Preferred emoji skin tone"
enableServerMachineStats: "Enable server hardware statistics"
enableIdenticonGeneration: "Enable Identicon generation"
embed: "Embed"
embedDescription: "Embed this post on your website by copying the code below:"
_sensitiveMediaDetection:
description: "Reduces the effort of server moderation through automatically recognizing

View file

@ -55,7 +55,7 @@
});
[].forEach.call(document.querySelectorAll('iframe.mastodon-embed'), function (iframe) {
[].forEach.call(document.querySelectorAll('iframe.embed'), function (iframe) {
// select unique id for each iframe
let id = 0;
let failCount = 0;

View file

@ -0,0 +1,85 @@
<template>
<MkModal
ref="modal"
:z-priority="'middle'"
@click="$refs.modal.close()"
@closed="$emit('closed')"
>
<div :class="$style.root">
<div :class="$style.title">
<p>{{ i18n.ts.embedDescription }}</p>
<MkCode :code="codeblock" lang="html" :inline="false"/>
<br/>
<MkButton
:class="$style.gotIt"
primary
full
@click="copyToClipboard(codeblock); $refs.modal.close()"
>{{ i18n.ts.copyContent }}</MkButton
>
<MkButton
:class="$style.gotIt"
primary
full
@click="$refs.modal.close()"
>{{ i18n.ts.gotIt }}</MkButton
>
</div>
</div>
</MkModal>
</template>
<script lang="ts" setup>
import { shallowRef } from "vue";
import MkModal from "@/components/MkModal.vue";
import MkButton from "@/components/MkButton.vue";
import MkCode from "@/components/MkCode.vue";
import { i18n } from "@/i18n";
import { host } from "@/config";
import copyToClipboard from "@/scripts/copy-to-clipboard";
const modal = shallowRef<InstanceType<typeof MkModal>>();
const props = withDefaults(
defineProps<{
id: string;
}>(),
{
id: "No ID provided!",
}
);
const codeblock = `<iframe src="https://${host}/notes/${props.id}/embed" class="embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script src="https://${host}/static-assets/embed.js" async="async"></script>`
</script>
<style lang="scss" module>
.root {
margin: auto;
position: relative;
padding: 32px;
min-width: 320px;
max-width: 480px;
box-sizing: border-box;
text-align: center;
background: var(--panel);
border-radius: var(--radius);
}
.title {
font-weight: bold;
}
.version {
margin: 1em 0;
}
.gotIt {
margin: 8px 0 0 0;
}
.releaseNotes {
> img {
border-radius: 10px;
}
}
</style>

View file

@ -926,6 +926,22 @@ export function post(props: Record<string, any> = {}) {
});
}
export function showEmbedDialog(props: {id: string}) {
return new Promise(() => {
popup(
defineAsyncComponent({
loader: () => import("@/components/MkEmbedDialog.vue"),
loadingComponent: MkWaitingDialog,
}),
{
...props,
},
{},
"closed",
);
});
}
export const deckGlobalEvents = new EventEmitter();
/*

View file

@ -476,6 +476,13 @@ export function getNoteMenu(props: {
action: share,
}
: undefined,
{
icon: "ph-code ph-bold ph-lg",
text: i18n.ts.embed,
action: os.showEmbedDialog({
id: appearNote.id,
}),
},
].filter((x) => x !== undefined);
}