Skip to content
Merged
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
6 changes: 6 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@
clearInterval(sendSources);
}, { once: true });

window.addEventListener("message", function(event) {
if (event.data && event.data.gistId && /^[0-9a-f]+$/.test(event.data.gistId)) {
window.location.search = "gist=" + event.data.gistId;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to worry about this clobbering other query string parameters? I haven’t worked out what the session one does yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just went with this because that's how all the current links work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is supposed to preserve session, which saves your editor to local state.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, of course.

}
});

return $iframe;
}
</script>
Expand Down
14 changes: 13 additions & 1 deletion client/js/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,25 @@
};
}

var parent;

document.addEventListener("DOMContentLoaded", function() {
window.addEventListener("message", function(event) {
event.source.postMessage("trypurescript", "*");
parent = event.source;
parent.postMessage("trypurescript", "*");
var file = evalSources(event.data)("<file>");
if (file.main && typeof file.main === "function") {
file.main();
}
}, { once: true });
}, { once: true });

document.addEventListener("click", function(event) {
if (parent && event.target.nodeName === "A" && event.target.hostname === "gist.github.com") {
event.preventDefault();
parent.postMessage({
gistId: event.target.pathname.split("/").slice(-1)[0]
}, "*");
}
}, false);
})();