Skip to content

Instantly share code, notes, and snippets.

@sbalko
Created March 16, 2016 09:10
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 sbalko/0edc345c8ffc4564b8e6 to your computer and use it in GitHub Desktop.
Save sbalko/0edc345c8ffc4564b8e6 to your computer and use it in GitHub Desktop.
Asynchronously loading first jQuery and then the Clipchamp API
<html>
<head>
<script async src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
</head>
<body>
<!-- Build up your initial document statically here. -->
<script type="text/javascript">
(function waitFor(condition, callback) {
(function poll() {
if (condition()) return callback();
else setTimeout(poll, 100);
})();
})(function() {
return typeof $ === 'function';
}, function() {
$('body').append('<script src="https://api.clipchamp.com/YOUR_API_KEY/button.js"></script>');
waitFor(function() {
return !!$.clipchamp;
}, function() {
// use the Clipchamp API with jQuery here
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment