Skip to content

Commit 1ff0ed7

Browse files
committed
test submit to parent
1 parent 386e6d7 commit 1ff0ed7

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Test Submit to Parent</title>
7+
<link rel="stylesheet" href="styles.css">
8+
</head>
9+
<body>
10+
<div class="container">
11+
<h1>Test Submit to Parent</h1>
12+
<div class="description">
13+
<p>This test application demonstrates how to embed sortingview/figurl in an iframe and receive messages from it. You can:</p>
14+
<ol>
15+
<li>Edit the curation in the embedded view below</li>
16+
<li>Click the "Submit to Parent" button</li>
17+
<li>View the received message details in the messages section below</li>
18+
</ol>
19+
<p>This setup is useful when embedding sortingview within a larger application that needs to receive curation updates.</p>
20+
</div>
21+
<div class="iframe-container">
22+
<iframe
23+
src="https://figurl.org/f?v=npm://@fi-sci/figurl-sortingview@12/dist&d=sha1://c17199c4d56f0119e108117535eca5a410a8fa5b&s={%22sortingCuration%22:%22gh://AllenNeuralDynamics/ephys-sorting-manual-curation/main/behavior_751004_2024-12-19_11-50-31/experiment1_Record%20Node%20104%23Neuropix-PXI-100.ProbeA_recording1/kilosort4/curation.json%22}&label=behavior_751004_2024-12-19_11-50-31%20-%20experiment1_Record%20Node%20104%23Neuropix-PXI-100.ProbeA_recording1%20-%20kilosort4%20-%20Sorting%20Summary&zone=aind"
24+
width="100%"
25+
height="900"
26+
frameborder="0"
27+
></iframe>
28+
</div>
29+
<div class="messages-container">
30+
<h2>Received Messages:</h2>
31+
<div id="messages"></div>
32+
</div>
33+
</div>
34+
<script src="script.js"></script>
35+
</body>
36+
</html>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
const messagesContainer = document.getElementById('messages');
3+
4+
// Function to add a new message to the container
5+
function addMessage(message) {
6+
const messageElement = document.createElement('div');
7+
messageElement.className = 'message';
8+
9+
// Try to stringify objects for better display
10+
let messageText;
11+
try {
12+
messageText = typeof message === 'object'
13+
? JSON.stringify(message, null, 2)
14+
: String(message);
15+
} catch (error) {
16+
messageText = 'Unable to display message: ' + error.message;
17+
}
18+
19+
// Create a pre element for formatted JSON display
20+
const preElement = document.createElement('pre');
21+
preElement.textContent = messageText;
22+
messageElement.appendChild(preElement);
23+
24+
// Add the message at the top of the container
25+
messagesContainer.insertBefore(messageElement, messagesContainer.firstChild);
26+
}
27+
28+
// Listen for messages from the iframe
29+
window.addEventListener('message', (event) => {
30+
// Check if the message is from the expected origin
31+
if (!event.origin.match(/^https?:\/\/(.*\.)?figurl\.org$/)) {
32+
console.warn('Received message from unexpected origin:', event.origin);
33+
return;
34+
}
35+
36+
// Log the raw event for debugging
37+
console.log('Received message event:', event);
38+
39+
// Add the message data to the display
40+
addMessage({
41+
origin: event.origin,
42+
data: event.data,
43+
timestamp: new Date().toISOString()
44+
});
45+
});
46+
47+
// Add initial message
48+
addMessage('Listening for messages...');
49+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.container {
2+
max-width: 1200px;
3+
margin: 0 auto;
4+
padding: 20px;
5+
font-family: Arial, sans-serif;
6+
}
7+
8+
.description {
9+
background-color: #f8f9fa;
10+
padding: 20px;
11+
border-radius: 4px;
12+
margin-bottom: 20px;
13+
line-height: 1.5;
14+
}
15+
16+
.description ol {
17+
margin: 15px 0;
18+
padding-left: 20px;
19+
}
20+
21+
.description li {
22+
margin-bottom: 8px;
23+
}
24+
25+
h1 {
26+
text-align: center;
27+
color: #333;
28+
}
29+
30+
.iframe-container {
31+
margin: 20px 0;
32+
border: 1px solid #ccc;
33+
border-radius: 4px;
34+
}
35+
36+
.messages-container {
37+
margin-top: 20px;
38+
padding: 20px;
39+
background-color: #f5f5f5;
40+
border-radius: 4px;
41+
}
42+
43+
#messages {
44+
margin-top: 10px;
45+
padding: 10px;
46+
background-color: white;
47+
border: 1px solid #ddd;
48+
border-radius: 4px;
49+
min-height: 100px;
50+
max-height: 300px;
51+
overflow-y: auto;
52+
}
53+
54+
.message {
55+
padding: 8px;
56+
margin: 8px 0;
57+
border-bottom: 1px solid #eee;
58+
word-wrap: break-word;
59+
}
60+
61+
.message:last-child {
62+
border-bottom: none;
63+
}

0 commit comments

Comments
 (0)