Forum Discussion

JimLeichliter's avatar
JimLeichliter
Community Member
14 years ago

Best place to put JavaScript functions for publishing

I'm new to Articulate and Storyline.  I have a few custom JavaScript functions that I use and would like to put them into one of the Storyline publishing templates so they're available every time I publish rather than having to copy/paste them into the JS editor in Storyline every time.  Is there a best practice or a particular JS template file I can use for placing customized JS functions? TIA!

16 Replies

  • MarkW's avatar
    MarkW
    Community Member

    I'm currently using jsPDF to make dynamic reports, and the current process requires me to edit the story.html file to to add the following lines of code:

    • <script src="js/jspdf.debug.js" type="application/javascript"></script>
    • <script src="js/createPDF.js" type="application/javascript"></script>
    • <script src="js/OpenSans-normal.js" type="module"></script>

    Can I use the WebObjects method to load these scripts? If so, could you tell me what it would look like? Any help is appreciated.

    • BrentWilliam187's avatar
      BrentWilliam187
      Community Member

      What I do to include scripts automatically is go to my master slide create an object out of frame and then give a trigger when user clicks to open the file in a new window.

      This causes SL to grab that file regardless and add it to the /story_content/external_files folder.

      Then I just use JS to append the scripts to the head of the html page on the master slide like so

      const s = document.createElement(script);
      s.src = story_content/external_files/[FILENAME].js
      document.querySelector('head').appendChild(s);

      If I have multiple files I will create an array with the files names and loop it instead to save writing redundant code.