Skip to content

Commit dcc4790

Browse files
committed
Add playground links to most examples. Only does expansion, at least for now.
Fixes #48.
1 parent 4af65b6 commit dcc4790

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

common/common.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ require(["core/pubsubhub"], (respecEvents) => {
171171
require(["core/pubsubhub"], (respecEvents) => {
172172
"use strict";
173173
respecEvents.sub('end-all', (documentElement) => {
174+
// Add example button selection logic
174175
for (const button of document.querySelectorAll(".ds-selector-tabs .selectors button")) {
175176
button.onclick = () => {
176177
const ex = button.closest(".ds-selector-tabs");
@@ -180,6 +181,18 @@ require(["core/pubsubhub"], (respecEvents) => {
180181
ex.querySelector("." + button.dataset.selects).classList.add("selected");
181182
}
182183
}
184+
185+
// Add playground links
186+
for (const link of document.querySelectorAll("a.playground")) {
187+
// First pre element of aside
188+
const pre = link.closest("aside").querySelector("pre");
189+
const content = unComment(document, pre.textContent)
190+
.replace(/(\*\*\*\*|####)/g, '');
191+
link.setAttribute('aria-label', 'playground link');
192+
link.setAttribute('href',
193+
'https://json-ld.org/playground-dev/#startTab=tab-expanded&json-ld=' +
194+
encodeURI(content));
195+
}
183196
});
184197
});
185198

0 commit comments

Comments
 (0)