Browse Source

first commit, basic embed + message passing

add-lib
Sanjay Bhangar 6 years ago
commit
1fa71c7474
  1. 1
      README.md
  2. 44
      index.html

1
README.md

@ -0,0 +1 @@
Experiments and examples using Pad.ma Embeds

44
index.html

@ -0,0 +1,44 @@
<!doctype html>
<html>
<head>
</head>
<body>
<iframe id="padembed" width="640" height="360" name="iframename" src="https://pad.ma/AGR/editor/00:04:55.800,00:00:21.880,00:04:55.800#embed" frameborder="0" allowfullscreen></iframe>
<script>
console.log('hello');
const $iframe = document.getElementById('padembed');
window.addEventListener('message', listener, false);
function listener(event) {
const data = JSON.parse(event.data);
if (data.event === 'init') document.getElementById(data.target).isInit = true;
console.log('received event', event);
console.log('name', event.data.name);
}
$iframe.addEventListener('load', () => {
console.log('iframe loaded');
let timeout;
function init() {
console.log('init called');
if ($iframe.isInit) {
clearTimeout(timeout);
return;
}
$iframe.contentWindow.postMessage(JSON.stringify({
data: {
oxid: 'padembed'
},
event: 'init'
}), '*');
timeout = setTimeout(init, 250);
}
init();
});
</script>
</body>
</html>
Loading…
Cancel
Save