Created
August 27, 2018 17:26
-
-
Save colynb/5b7c89cf26eebe79e7a33e5ca6545ac7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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