/*
This file is stored in a js folder, on the same level as the published folder.
This script hooked in first slide of captivate project with:
$("body").append("");
Dependencies:
In Captivate, a naming convention applied to the progress bar multistate object.
on each frame that implements the progress bar, the multistate object should be named using the prefix 'progress_' and the suffix which is the slide number.
ie progress_15 for the bar on the 15th slide.
Add a javascript action to the frame and call the function that starts initialises the progress bar : initialiseProgress();
From that moment, the Captivate enterFrame event listener will automatically trigger the progressBarStateChange() function,
which calculates the percentage of progress, rounds down to blocks of 10, and triggers the change of the progress bar.
More info at https://jrdesign.com.au/blog
$("body").append("");
initialiseProgress();
*/
console.log("JProgress Bar Javascript included");
// Captivate Total Slide Count : cpInfoSlideCount
var cpSlideCount
// Captivate Current Slide Number: cpInfoCurrentSlide
var cpCurrentSlide;
/* ----------------------------------------- */
// Initialisation
/* ----------------------------------------- */
function initialiseProgress(){
console.log(":: initialiseProgress ::");
// get the total number of slides
cpSlideCount = getCpVariable("cpInfoSlideCount");
}
/* ----------------------------------------- */
// Captivate Multistate Object State Changer
/* ----------------------------------------- */
function progressBarStateChange(){
console.log(":: msoStateChange :: ");
// get the rounded down value of progress
var currentProgress = calculateProgress()
// change the state of the progress bar multistate object in Captivate. (undocumented function)
cp.changeState("progress_"+cpCurrentSlide,"step_"+currentProgress); // hardcoded value TBC
}
/* ----------------------------------------- */
// Calculate percentage of progress
/* ----------------------------------------- */
function calculateProgress(){
console.log(":: calculateProgress :: ");
cpCurrentSlide = getCpVariable("cpInfoCurrentSlide");
var progress = Math.round(Math.floor((cpCurrentSlide/cpSlideCount)*100)/10)*10;
return progress;
}
/* ----------------------------------------- */
// GETTERS AND SETTERS
/* ----------------------------------------- */
/* ----------------------------------------- */
// Get current slide number
/* ----------------------------------------- */
function getCurrentSlide(){
return getCpVariable("cpInfoCurrentSlide");
}
/* ----------------------------------------- */
// Captivate Variable Getter/Setter
/* ----------------------------------------- */
function setCpVariable(p_var,p_val){
console.log("setCpVariable: "+p_var+" : "+p_val);
window.cpAPIInterface.setVariableValue(p_var,p_val);
}
function getCpVariable(p_var){
var cpVar = window.cpAPIInterface.getVariableValue(p_var);
console.log("getCpVariable: "+p_var+" : "+cpVar);
return cpVar;
}
/* ----------------------------------------- */
// Captivate Event Listeners
/* ----------------------------------------- */
// executed when user enters a slide
window.cpAPIEventEmitter.addEventListener(
"CPAPI_SLIDEENTER",
function(e){
// update the progress bar
progressBarStateChange();
}
);
/* ----------------------------------------- */
// Boot up the Code
/* ----------------------------------------- */
initialiseProgress();