Created
March 3, 2017 23:16
-
-
Save eob/7b8ca9107ff04f06bc59813a0d37a1fc to your computer and use it in GitHub Desktop.
Including External Javascript Libraries in Cloudstitch
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
/* | |
* 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