I've been using some additional javascript library files, but I'm doing lots of testing and adding them in each time is taking too long and I would like them to load automatically.
Can I just add them into a function which will load as part of user.js with all the other functions?
Is there a way to do something equivalent to this?
Couple of ways to do this. If you're referencing libraries on CDN, here's the way I do this in a Javascript Trigger that runs when the timeline starts (added to user.js on publish). In this example, I added the library files to a Web Object, published to reveal the relative path, and added those paths. If using a CDN, you'd change the add_script parameter to your absolute CDN reference.
function add_script(scriptURL,oID) { var scriptEl = document.createElement("script"); var head=document.getElementsByTagName('head')[0]; scriptEl.type = "text/javascript"; scriptEl.src = scriptURL; scriptEl.id=oID; head.appendChild(scriptEl);}
//only want to add these once! if(document.getElementById('jquery')==null){ add_script("story_content/WebObjects/5rmVJdSA7hX/jquery-1.11.3.min.js","jquery"); add_script("story_content/WebObjects/5rmVJdSA7hX/taffy-min.js","taffy");
You *could* also simply paste the contents of the library into a Javascript trigger. This would have the same effect. But be aware that a trigger won't let you paste in more than 15K or so at a time. For small libraries, this works OK.
Adding any of your library files to a folder and adding an empty index.html file will let you bring these in as "baggage". Publish, explore the story_content/webobjects folder and grab the path and Bob's your uncle.
It's the file that the WebObject needs to launch. If there isn't an index.html file, the folder won't be ingested. I import a WebObject containing my baggage into a slide that isn't accessed, in a scene placed "Off to the side"
If you don't include an index.html file, the WebObject workflow won't complete.
I ran into some problems using the WebObjects method - for some reason it
gave different locations to one of the libraries without me realising (I
must have written something wrong). So I went back to using the
'external
8 Replies
Hey Luke -
Couple of ways to do this. If you're referencing libraries on CDN, here's the way I do this in a Javascript Trigger that runs when the timeline starts (added to user.js on publish). In this example, I added the library files to a Web Object, published to reveal the relative path, and added those paths. If using a CDN, you'd change the add_script parameter to your absolute CDN reference.
function add_script(scriptURL,oID) {
var scriptEl = document.createElement("script");
var head=document.getElementsByTagName('head')[0];
scriptEl.type = "text/javascript";
scriptEl.src = scriptURL;
scriptEl.id=oID;
head.appendChild(scriptEl);}
//only want to add these once!
if(document.getElementById('jquery')==null){
add_script("story_content/WebObjects/5rmVJdSA7hX/jquery-1.11.3.min.js","jquery");
add_script("story_content/WebObjects/5rmVJdSA7hX/taffy-min.js","taffy");
}
You *could* also simply paste the contents of the library into a Javascript trigger. This would have the same effect. But be aware that a trigger won't let you paste in more than 15K or so at a time. For small libraries, this works OK.
Thanks very much this is great.
By CDN do you mean something that would start with http://? I intend to put
the js files into story
Yeah. That's what I meant by CDN:)
Adding any of your library files to a folder and adding an empty index.html file will let you bring these in as "baggage". Publish, explore the story_content/webobjects folder and grab the path and Bob's your uncle.
Why is the index.html file needed?
It's the file that the WebObject needs to launch. If there isn't an index.html file, the folder won't be ingested. I import a WebObject containing my baggage into a slide that isn't accessed, in a scene placed "Off to the side"
If you don't include an index.html file, the WebObject workflow won't complete.
Steve
Success! - Thanks so much for this.
I ran into some problems using the WebObjects method - for some reason it
gave different locations to one of the libraries without me realising (I
must have written something wrong). So I went back to using the
'external
One question Steve - my intermittent error has come back.
I had it working and then added a slide (without changing anything else)
and this error came back:
Uncaught ReferenceError: jsPDF is not defined(anonymous function) @
jspdf.plugin.split
This discussion is closed. You can start a new discussion or contact Articulate Support.