Skip to content

Instantly share code, notes, and snippets.

@colynb
Created August 27, 2018 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colynb/5b7c89cf26eebe79e7a33e5ca6545ac7 to your computer and use it in GitHub Desktop.
Save colynb/5b7c89cf26eebe79e7a33e5ca6545ac7 to your computer and use it in GitHub Desktop.
On client page
```html
<re-widget type="youtube" src="https://www.youtube.com/embed/TwAFQZLK79A"></re-widget>
<script>
(function (fn) {
var d = document, s = d.createElement('script');
s.onload = fn; d.head.appendChild(s); s.src = 'embed.js';
})(function () {
MyLib.init({
message: 'Hello'
})
});
</script>
```
embed.js
```
var MyLib = {
config: {
name: 'Hello'
},
init: function(config) {
this.config = config
var widgets = document.querySelectorAll('re-widget')
widgets.forEach(function(e) {
e.innerHTML = ''
var f = document.createElement('iframe')
f.style.width = '100%'
f.style.height = '100vh'
f.frameBorder = 0
f.allowfullscreen = true
f.src = e.getAttribute('src')
e.appendChild(f)
console.log(e.attributes)
})
}
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment