External JavaScript source

Jun 10, 2014

Hi,

is there a simple solution in SL to include an external js script file? I would like to implement a timer from jquery.

Thanks a lot,

Sophia

10 Replies
Andrew Gee

Hi Sophia,

I have wanted the same but am unable to figure this out.

I have had to load all content into the output folder and this has included html docs and images as well as JS libraries.  Also I have had to add the same content to the output zip file when publishing to LMS.

So yes as far as I know the output folder needs to have the content in it.

I am not aware of any other solutions.

If someone else has a solution please let us know!!!

Steve Flowers

You can include a JS file in a Web object and reference that file from a JavaScript trigger, writing the include to the header through DOM. This adds your js file to the story file in every publish so you don't have to do any "post-publish surgery". Here's an example. You'll only want to add this once but it can be triggered from a master slide, handling the single run in JS.

Add your web object to a non-loading slide. Right click the web object and select Open. This will temp launch and reveal the GUID in the address line. 

this.oLocation="story_content/WebObjects/66vjsN26Fjn/";

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);

}

if(document.getElementById('libraryload')==null){

add_script(oLocation+"script/yourlibrary-jsmin.js","libraryload");

}

This works great in the Flash output. Haven't tested extensively in HTML5.

Andrew Gee

Hi Steve,

I am new to JS and HTML so might be a bit confused but understand the JS advice you have given and will try this for the JS library (sorttable.js) that I need for my HTML doc.

The HTML doc  references to approx 16 images and many SL variables.  Can I put the images on the non-loading slide as I have had to put these in the output folder as well for the HTML doc to work properly.  And if so how would they be referenced in the HTML doc.

Not sure if this can be done as well.

Thanks

Andrew

Steve Flowers

Hmm... I'm assuming that your sortable elements are going to appear within a Web Object anyway. Might be best just to keep everything in the Web Object.

You can transport anything in your Web Object and it'll be saved in the Story file and published every time.

http://community.articulate.com/forums/p/28295/153557.aspx

Andrew Gee

Hi Steve,

Thank you for the prompt response and previous advice, I will have play around using your advice and see what I can come up with.

I agree with the sortable elements being in the web object and this is much easier given my knowledge of HTML and JS is limited but steadily growing.

At the moment everything works fine and I just have to ensure I load everything into the output folder once published which isn't a big deal to me but anything to make life easier is welcome.

Thanks again.

Andrew

Andrew Gee

Hi Steve,

Just an update on the above.

Having the extra content in a folder then referencing as a web object works very well when I publish to CD.

Does not work when I publish to web but that might be that fact I am on a secure network with many restrictions.

At least I do not need to load everything into the output folder anymore and the HTML docs load fine from there also.

Thanks again.

Andrew

Andrew Gee

Hi Steve,

No I am not uploading to server to test and yes it is the Flash security but that's OK as long as I can get the unique folder ID when I publish to web and then JS works fine when republished to CD.  

This is just a personal project I have been working on to build my knowledge of JS and HTML with Storyline.   

I have other work specific projects that we have tested on the server via our LMS and java works fine as well.

The next test is on the iPad but have not done any testing on iPad as yet.

Will keep you posted on that in another thread if I encounter issues.

Cheers

Andrew

This discussion is closed. You can start a new discussion or contact Articulate Support.