Skip to content

Commit

Permalink
Merge pull request #1 from kennedn/pebble#162/unable-to-use-Clay-in-e…
Browse files Browse the repository at this point in the history
…mulator

Resolves pebble#162 - data URI now loads in iframe
  • Loading branch information
kennedn authored Jun 5, 2020
2 parents 1bf6db0 + 65106c7 commit b4a08b9
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions dev/emulator.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<title>Config Page Emulator</title>
</head>
<script>
// Must wait for onload for appendChild to work
window.onload = function () {
function getQueryParam(variable, defaultValue) {
var query = location.search.substring(1);
var vars = query.split('&');
Expand All @@ -22,13 +24,26 @@
var data = decodeURIComponent(location.hash.substring(1));

// Check if we dealing with a base64 encoded URI
if (data && data.charAt(0) !== '<') {
data = window.atob(data).replace('$$RETURN_TO$$', returnTo);
window.location.href = 'data:text/html;base64,' + encodeURIComponent(window.btoa(data));
} else if (data) {
data = data.replace('$$RETURN_TO$$', returnTo);
window.location.href = 'data:text/html;charset=utf-8,' + encodeURIComponent(data);
if (data) {
if (data.charAt(0) !== '<') {
data = window.atob(data).replace('$$RETURN_TO$$', returnTo);
data = 'data:text/html;base64,' + encodeURIComponent(window.btoa(data));
} else {
data = data.replace('$$RETURN_TO$$', returnTo);
data = 'data:text/html;charset=utf-8,' + encodeURIComponent(data);
}
// Create a new iframe element with our data URI
var iframe = document.createElement("iframe");
iframe.src = data;
// Make the iframe fill the entire display
iframe.frameborder = "0";
iframe.style = `position:fixed; top:0; left:0; bottom:0; right:0; width:100%; height:100%;
border:none; margin:0; padding:0; overflow:hidden; z-index:999999;`;
// Append iframe to body
document.body.appendChild(iframe);

}
};
</script>
<body>
</body>
Expand Down

0 comments on commit b4a08b9

Please sign in to comment.