-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.svelte
63 lines (53 loc) · 1.3 KB
/
index.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script>
import { tick } from "svelte";
let isModalOpen = false;
let hasWrapper = true;
const embedHtml = `
<blockquote class="twitter-tweet">
<p lang="en" dir="ltr">
we are all muppets now, but, like, OFFICIALLY <a
href="https://t.co/FX9Ir76yGi"
>
pic.twitter.com/FX9Ir76yGi
</a>
</p>
— Svelte Society 🧡 (@SvelteSociety)
<a
href="https://twitter.com/SvelteSociety/status/1386318870378532865?ref_src=twsrc%5Etfw"
>
April 25, 2021
</a>
</blockquote>
`;
async function handleModalOpen() {
isModalOpen = true;
await tick();
if (typeof twttr?.widgets?.load === "function") {
twttr.widgets.load();
}
}
function handleModalClose() {
isModalOpen = false;
}
</script>
<svelte:head>
<script async src="https://platform.twitter.com/widgets.js"></script>
</svelte:head>
<label>
<input type="checkbox" bind:checked={hasWrapper} />
Wrap
<code>@html</code>
in a div
</label>
<hr />
{#if isModalOpen && hasWrapper}
<div>
{@html embedHtml}
</div>
<button on:click={handleModalClose}>Close</button>
{:else if isModalOpen}
{@html embedHtml}
<button on:click={handleModalClose}>Close</button>
{:else}
<button on:click={handleModalOpen}>Open Modal</button>
{/if}