Javascript Background Audio - Here we go again

I use this frequenlty, used this just last month on a "Monthly Safety Topic" here at work.

This month, none of the Javascript element in my course are triggering AT ALL.

Slide 1 - we load the BGaudio music player

Slide 2 - Layer 1 - when you click EITHER of the "start" buttons (English or Spanish) it is supposed to start the bg music and close the left menu sidebar.  Neither thing happens.

Slide 20 - supposed to reopen the left menu sidebar.

Slide 20 - Comments buttons (Javascript link to open a Smartsheet) doesn't do anything

Throughout the entire course is a FEEDBACK link up in the top bar, it also doesn't do anything.

 

It appears as if all JS is simply "not working".   Any ideas why?

Published for review here: https://360.articulate.com/review/content/cd410153-1c8e-4a35-b886-bddbffe2a50f/review 

 

4 Replies
Matthew Bibby

There appears to be a lot of hard line breaks in your code (as indicated by the red dots in the example below):

Make sure you are using a code editor (or even Notepad in a pinch) and not Microsoft Word or similar to work on your code. Sometimes weird stuff happens.

If you replace the contents of the user.js file with the below I reckon you'll have more success:

function ExecuteScript(strId)
{
switch (strId)
{
case "6DCWHH4k2JJ":
Script1();
break;
case "5fYz4rlmY5m":
Script2();
break;
case "6ofFxIizOKe":
Script3();
break;
case "5WtbmFExNfx":
Script4();
break;
case "5bDtGWz0Nez":
Script5();
break;
case "5aRiS4PDyYA":
Script6();
break;
case "5cma1u2IVIL":
Script7();
break;
case "5wVQCrUyTZI":
Script8();
break;
case "5rWi5xi7cF8":
Script9();
break;
case "5eTTTQtuk4I":
Script10();
break;
case "5uCUlWFUNp9":
Script11();
break;
case "6Z44l8ifRYl":
Script12();
break;
case "6DWz2YofJSE":
Script13();
break;
case "5xjsU8B4X0x":
Script14();
break;
case "6XIuyBs5lIm":
Script15();
break;
case "6rELP0bPKcK":
Script16();
break;
case "6WeB4myVzg8":
Script17();
break;
case "6LSdYF9wyJA":
Script18();
break;
case "6bG6v92Hdud":
Script19();
break;
case "5pfO4z2ziF4":
Script20();
break;
case "6AOvbLcirhe":
Script21();
break;
case "66z4gNcUfHh":
Script22();
break;
}
}

function Script1()
{
var browser = function() {
// Return cached result if avalible, else get result then cache it.
if (browser.prototype._cachedResult)
return browser.prototype._cachedResult;

// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';

// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification);

// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;

// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;

// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;

// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;

return browser.prototype._cachedResult =
isOpera ? 'Opera' :
isFirefox ? 'Firefox' :
isSafari ? 'Safari' :
isChrome ? 'Chrome' :
isIE ? 'IE' :
isEdge ? 'Edge' :
isBlink ? 'Blink' :
"Don't know";
};
//put the results into Storyline in a variable called "browser"
var player = GetPlayer();
player.SetVar("browser", browser());

}

function Script2()
{
//load the scripts dynamically into the head of the document

function add_line() {
var line = document.createElement("audio");
var head=document.getElementsByTagName('body')[0];
line.type = "audio/mp3";
line.src="";
line.id="bgSong";
line.autoplay = true;
line.loop = true;
head.appendChild(line);
}

//but we only want to add these once!
if(document.getElementById('bgSong')==null){
add_line();
var audio = document.getElementById('bgSong');
audio.volume = 0.2;
}
}

function Script3()
{
$( ".menu-icon-wrapper" ).click();
}

function Script4()
{
//Left MENU sidebar
document.querySelector("#hamburger > div").click();
}

function Script5()
{
//Put name of student into variable "username"
//Construct a URL with the student's name included in variable "smartURL"

var feedbackform = "https://app.smartsheet.com/b/form/94b1b0fcfe814a39a805507d41700d77"

var player = GetPlayer();
var docname = document.title
player.SetVar("DocTitle", docname);

function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;

else if (win.parent == win) return null;

else return findLMSAPI(win.parent);
}

var lmsAPI = findLMSAPI(this);
var myName = lmsAPI.GetStudentName();
var array = myName.split(',');
var newName = array[1] + '%20' + array[0];
player.SetVar("username", array[1]); // username is your Storyline Variable

if (newName) {
player.SetVar("smartURL", feedbackform + "?Name=" + newName + "&Course=" + docname);
}else{
player.SetVar("smartURL", feedbackform + "?Course=" + docname);
}

var str = player.GetVar("smartURL");
var course = player.GetVar("Course");

if (str) {
//do nothing
} else if (course) {
player.SetVar("smartURL", feedbackform + "?Course=" + course);
} else {
player.SetVar("smartURL", feedbackform);
}
}

function Script6()
{
var browser = function() {
// Return cached result if avalible, else get result then cache it.
if (browser.prototype._cachedResult)
return browser.prototype._cachedResult;

// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';

// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification);

// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;

// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;

// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;

// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;

return browser.prototype._cachedResult =
isOpera ? 'Opera' :
isFirefox ? 'Firefox' :
isSafari ? 'Safari' :
isChrome ? 'Chrome' :
isIE ? 'IE' :
isEdge ? 'Edge' :
isBlink ? 'Blink' :
"Don't know";
};
//put the results into Storyline in a variable called "browser"
var player = GetPlayer();
player.SetVar("browser", browser());

}

function Script7()
{
//load the scripts dynamically into the head of the document

function add_line() {
var line = document.createElement("audio");
var head=document.getElementsByTagName('body')[0];
line.type = "audio/mp3";
line.src="";
line.id="bgSong";
line.autoplay = true;
line.loop = true;
head.appendChild(line);
}

//but we only want to add these once!
if(document.getElementById('bgSong')==null){
add_line();
var audio = document.getElementById('bgSong');
audio.volume = 0.2;
}
}

function Script8()
{
var audio = document.getElementById('bgSong');
audio.src="story_content/6LZ2SuLWsbL_44100_128_1.mp3";
audio.load();
audio.play();

}

function Script9()
{
//toggles the left MENU navigation popout
var myCode = function() {
// Add your custom code with `$` or `jQuery` here.
$( ".menu-icon-wrapper" ).click();
}
if (window.$ != null) { // If jQuery has already loaded, run myCode.

myCode();

} else { // Else, load jQuery and then run myCode.

var jQueryLoader = document.createElement("script");

jQueryLoader.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js";

jQueryLoader.onload = function() {

jQueryLoader.onload = null;

myCode();

}

document.head.appendChild(jQueryLoader);

}
$( ".menu-icon-wrapper" ).click();
}

function Script10()
{
var audio = document.getElementById('bgSong');
audio.src="story_content/6LZ2SuLWsbL_44100_128_1.mp3";
audio.load();
audio.play();

}

function Script11()
{
//toggles the left MENU navigation popout
var myCode = function() {
// Add your custom code with `$` or `jQuery` here.
$( ".menu-icon-wrapper" ).click();
}
if (window.$ != null) { // If jQuery has already loaded, run myCode.

myCode();

} else { // Else, load jQuery and then run myCode.

var jQueryLoader = document.createElement("script");

jQueryLoader.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js";

jQueryLoader.onload = function() {

jQueryLoader.onload = null;

myCode();

}

document.head.appendChild(jQueryLoader);

}
$( ".menu-icon-wrapper" ).click();
}

function Script12()
{
var audio = document.getElementById('bgSong');
audio.src="story_content/6LZ2SuLWsbL_44100_128_1.mp3";
audio.load();
audio.play();
}

function Script13()
{
var audio = document.getElementById('bgSong');

audio.pause();
}

function Script14()
{
var audio = document.getElementById('bgSong');

audio.play();
}

function Script15()
{
var audio = document.getElementById('bgSong');
audio.src="story_content/6fjhWIzHqg1_44100_128_1.mp3";
audio.load();
audio.play();
}

function Script16()
{
//Left MENU sidebar
document.querySelector("#hamburger > div").click();
}

function Script17()
{
//Left MENU sidebar
document.querySelector("#hamburger > div").click();
}

function Script18()
{
//Open the smartURL link created earlier

var player = GetPlayer();
var win = window.open(player.GetVar("smartURL"));
}

function Script19()
{
//Open the smartURL link created earlier, or create one as a fallback

var feedbackform = "https://app.smartsheet.com/b/form/94b1b0fcfe814a39a805507d41700d77";
var player = GetPlayer();
var str = player.GetVar("smartURL");
var course = player.GetVar("Course");

if (str) {
var win = window.open(str);
} else if (course) {
var win = window.open(feedbackform + "?Course=" + course);
} else {
var win = window.open(feedbackform);
}

}

function Script20()
{
//Open the smartURL link created earlier, or create one as a fallback

var feedbackform = "https://app.smartsheet.com/b/form/94b1b0fcfe814a39a805507d41700d77";
var player = GetPlayer();
var str = player.GetVar("smartURL");
var course = player.GetVar("Course");

if (str) {
var win = window.open(str);
} else if (course) {
var win = window.open(feedbackform + "?Course=" + course);
} else {
var win = window.open(feedbackform);
}

}

function Script21()
{
//Open the smartURL link created earlier, or create one as a fallback

var feedbackform = "https://app.smartsheet.com/b/form/94b1b0fcfe814a39a805507d41700d77";
var player = GetPlayer();
var str = player.GetVar("smartURL");
var course = player.GetVar("Course");

if (str) {
var win = window.open(str);
} else if (course) {
var win = window.open(feedbackform + "?Course=" + course);
} else {
var win = window.open(feedbackform);
}

}

function Script22()
{
var player = GetPlayer();

//Click sound
var tickval = player.GetVar("JSTick");
tickval = tickval * -1;
player.SetVar("JSTick", tickval);

//Open the smartURL link created earlier, or create one as a fallback

var feedbackform = "https://app.smartsheet.com/b/form/94b1b0fcfe814a39a805507d41700d77";
var str = player.GetVar("smartURL");
var course = player.GetVar("Course");

if (str) {
var win = window.open(str);
} else if (course) {
var win = window.open(feedbackform + "?Course=" + course);
} else {
var win = window.open(feedbackform);
}

}