Skip to content

Instantly share code, notes, and snippets.

@eob
Created March 3, 2017 23:16
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 eob/7b8ca9107ff04f06bc59813a0d37a1fc to your computer and use it in GitHub Desktop.
Save eob/7b8ca9107ff04f06bc59813a0d37a1fc to your computer and use it in GitHub Desktop.
Including External Javascript Libraries in Cloudstitch
/*
* In the Javascript part of your widget.. find the afterRender hook.
*/
module.exports.afterRender = function(elem, data) {
/*
* Now we manually create a SCRIPT tag
*/
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js';
/*
* Here's the important part: we have to wait for the JS to load before we
* do anything with it.
*/
script.onload = function () {
// Now we can use jQuery! The `elem` variable is the root DOM Node of our widget.
var $elem = jQuery(elem);
}
/*
* Now we add the SCRIPT tag to the head
*/
document.head.appendChild(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment