Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/playground/element.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mdn-modal {
flex-direction: column;
gap: 0.5rem;

&:first-child {
&:not(:last-child) {
margin-bottom: 1rem;
}
}
Expand Down
31 changes: 30 additions & 1 deletion components/playground/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ ${"```"}`,
}
}

async _copyDataUrl() {
const controller = this._controller.value;
if (controller) {
const { css, html, js } = controller.code;
let code = `<!doctype html>`;
if (css) code += `<style>${css}</style>`;
if (html) code += html;
if (js) code += `<script>${js}</script>`;
// encode non-space whitespace
code = code.replaceAll(/[^\S ]/g, (ch) => encodeURIComponent(ch));
await navigator.clipboard.writeText(
`data:text/html;charset=utf-8,${code}`,
);
}
}

async _createPermalink() {
const controller = this._controller.value;
if (controller) {
Expand Down Expand Up @@ -372,10 +388,22 @@ ${"```"}`,
<mdn-modal ${ref(this._shareModal)} class="share">
<section>
<h2>${this.l10n`Share Markdown`}</h2>
<mdn-button variant="secondary" @click=${this._copyMarkdown}
<mdn-button
variant="secondary"
@click=${this._copyMarkdown}
data-glean-id="playground: copy-markdown"
>${this.l10n`Copy markdown to clipboard`}</mdn-button
>
</section>
<section>
<h2>${this.l10n`Share Data URL`}</h2>
<mdn-button
variant="secondary"
@click=${this._copyDataUrl}
data-glean-id="playground: copy-data-url"
>${this.l10n`Copy data URL to clipboard`}</mdn-button
>
</section>
<section>
<h2>${this.l10n`Share your code via Permalink`}</h2>
${this._user.render({
Expand All @@ -389,6 +417,7 @@ ${"```"}`,
<mdn-button
variant="secondary"
@click=${this._copyPermalink}
data-glean-id="playground: copy-permalink"
>${this.l10n`Copy to clipboard`}</mdn-button
>
`
Expand Down
Loading