Skip to content

Commit 8e6c723

Browse files
committed
button fixes
1 parent cbffc55 commit 8e6c723

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

docs/assets/invariant.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ body {
2727
position: relative;
2828
}
2929

30-
.trace-iframe {
31-
width: 100%;
32-
border: none;
33-
height: 500px;
34-
}
35-
3630
h1 {
3731
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
3832
}

docs/assets/js/highlight.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
BASE_URL = 'http://localhost/';
22

3-
function changeTraceElements(codeElements) {
3+
function changeElements(codeElements, endpoint) {
44
// Add a button to each pre element
55
codeElements.forEach(function(codeElement) {
66

77
// replace the code element with an iframe
88
const textContent = codeElement.textContent || codeElement.innerText;
99
const encodedContent = btoa(textContent);
10-
const iframe = document.createElement('iframe', { id: 'traceview-' + encodedContent });
11-
iframe.src = `${BASE_URL}traceview?trace=${encodedContent}`;
10+
// get a UUID
11+
const id = crypto.randomUUID().toString();
12+
const iframe = document.createElement('iframe', { id: id });
13+
iframe.src = `${BASE_URL}embed/${endpoint}=${encodedContent}&id=${id}`;
1214
codeElement.replaceWith(iframe);
1315

1416
window.addEventListener('message', function(event) {
15-
if (event.data.type === 'resize') {
16-
console.log('resize', event.data);
17+
//check which element the message is coming from
18+
if (event.data.type === 'resize' && event.data.id === id) {
1719
iframe.style.height = event.data.height + 'px';
1820
}
1921
});
2022

2123
});
2224
}
2325

24-
2526
document.addEventListener('DOMContentLoaded', function() {
2627
// check if BASE_URL is defined and reachable
2728
fetch(`${BASE_URL}`)
@@ -34,8 +35,8 @@ document.addEventListener('DOMContentLoaded', function() {
3435
.then(data => {
3536
// if we can reach it, add buttons to trace and guardrail elements
3637
// currently disabled as the traceview endpoint is not yet enabled on explorer
37-
//changeTraceElements(document.querySelectorAll('div.language-trace'))
38-
//changeGuardrailElements(document.querySelectorAll('div.language-guardrail'))
38+
changeElements(document.querySelectorAll('div.language-trace'), 'traceview?trace')
39+
changeElements(document.querySelectorAll('div.language-guardrail'), 'playground?policy')
3940
})
4041
.catch(error => {
4142
console.error('There was a problem with the fetch operation:', error);

0 commit comments

Comments
 (0)