Enabling the Next Page Button after Media Completion in Training Studio
February 12, 2013 Leave a comment
One of our Training Studio customers wanted to disable the “Next Page” button on a “Media Full Screen” template until the video was completed. We had the hooks in there and thus this was an easy change. The relevant “load” code is shown below.
$(function () { // template population code omitted var videoId = document.getElementById("player_0"); if (videoId != null) { // can play HTML5 video videoId.addEventListener("ended", contentCompleted); } else { contentCompleted(); } // bind keyboard events $(document).keydown(parent.ImplementKeyDown); });
The $() means that the jQuery will call the function after the page fully loads. We then get our hands on the HTML object that we use to play our HTML 5 audio or video. If the browser is not HTML 5 capable, then we call the contentCompleted function right away so that the user is not stuck. We then handle the ended event with the addEventListener method. We tell it to call the contentCompleted function when the video is ended. This function is shown below.
function contentCompleted(e) { // show completion image parent.CompletionImageRef.show(); //enable next page button parent.SetBtnStatus(parent.NextButtonRef,"Next",true,true); }
We make two function calls to our main JavaScript file. We refer to it via parent since it is attached to the parent object (the templates are shown in an iFrame of the page – so the page is the parent). The CompletionImageRef.show() line shows our completion image while the SetBtnStatus method sets the Next page button to enabled (and keeps it visible).