Created
March 28, 2018 23:15
-
-
Save cachrisman/ff5581b1df58c3f070d4bd09252e8eec to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<!-- UI Extensions CSS --> | |
<link rel="stylesheet" href="//contentful.github.io/ui-extensions-sdk/cf-extension.css"> | |
<!-- UI Extensions SDK --> | |
<script src="//contentful.github.io/ui-extensions-sdk/cf-extension-api.js"></script> | |
<style> | |
</style> | |
</head> | |
<body> | |
<!-- Custom markup of the UI Extension --> | |
<button id="randomImage" class="cf-btn-primary">Generate Random Image</button> | |
<img src="" id="image"> | |
<!-- Custom logic of the UI Extension --> | |
<script> | |
window.contentfulExtension.init(extension => { | |
document.getElementById('randomImage').addEventListener('click', () => { | |
extension.window.updateHeight(1600) | |
const key = 'unsplash'; | |
const url = `https://source.${key}.com/random/2560x1440?random-${new Date().getTime()}`; | |
let image = document.getElementById('image') | |
image.src = url; | |
console.log(url); | |
extension.entry.fields['url'].setValue(url); | |
}) | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment