Skip to content

Commit 086d452

Browse files
committed
Add permalink popup & copy button.
1 parent 54935bc commit 086d452

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

playground/next/editor.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ window.app = createApp({
349349
}
350350
return '';
351351
},
352+
get permalinkURL() {
353+
const url = new URL(window.location);
354+
const hash = new URLSearchParams();
355+
hash.set('json-ld', JSON.stringify(this.doc));
356+
hash.set('startTab', `tab-${this.outputTab}`);
357+
url.hash = hash.toString();
358+
return url.toString();
359+
},
352360
get sideDoc() {
353361
if (this.outputTab === 'framed') {
354362
return 'frameDoc';
@@ -370,6 +378,14 @@ window.app = createApp({
370378
return 'Context URL';
371379
}
372380
},
381+
copyPermalink() {
382+
const url = this.permalinkURL;
383+
navigator.clipboard.writeText(url).then(() => {
384+
console.log('Permalink copied to clipboard:', url);
385+
}).catch(err => {
386+
console.error('Failed to copy permalink:', err);
387+
});
388+
},
373389
// methods
374390
async retrieveDoc(_editor, docVar, url) {
375391
try {

playground/next/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ <h2 class="ui massive header">JSON-LD Playground</h2>
7070
</div>
7171

7272
<div class="ui right floated buttons">
73+
<button id="permalink" class="ui icon button" data-position="left center">
74+
<i class="icon linkify"></i>
75+
</button>
76+
<div class="ui popup" style="min-width: 20em;">
77+
<div class="ui top attached label">Share this</div>
78+
<div class="ui fluid action input">
79+
<input type="text" readonly v-model="permalinkURL" @focus="$event.target.select()">
80+
<button class="ui icon button" @click="copyPermalink()">
81+
<i class="icon copy"></i>
82+
</button>
83+
</div>
84+
</div>
7385
<button id="keyboard-shortcuts" class="ui icon button" data-position="left center">
7486
<i class="icon keyboard"></i>
7587
</button>

0 commit comments

Comments
 (0)