Navigation Restricted or Locked using HTML5

Oct 22, 2013

I've written some simple Javascript that allows the implementation of 'Restricted' navigation in the HTML5 Storyline player menu. You can use the code as I have it here (only run the code once), or you can modify it to fully restrict navigation as 'Locked'.

Restricted Navigation:

To restrict Menu navigation to slide previously viewed, use the code below.

    if (player.useCanvas) {

            // [name] is the name of the event "click", "mouseover", .. 

            // same as you'd pass it to bind()

            // [fn] is the handler function

            $.fn.bindFirst = function(name, fn) {

                // bind as you normally would

                // don't want to miss out on any jQuery magic

                this.bind(name, fn);

                // Thanks to a comment by @Martin, adding support for

                // namespaced events too.

                var handlers = this.data('events')[name.split('.')[0]];

                // take out the handler we just inserted from the end

                var handler = handlers.pop();

                // move it at the beginning

                handlers.splice(0, 0, handler);

            };

            listitems = $('#slide_list li');

            $.each(listitems,function(listitems,k){

                                j=$(k);

                                if(j.hasClass("has_children"))

                                    return 1;

                                j.bindFirst("click",function(event){if(!$(k).hasClass("visited"))event.stopImmediatePropagation();});

                            });

    }

Locked Navigation:
To 'Lock' the use of the Menu for navigation use the code below.
    if (player.useCanvas) {
            listitems = $('#slide_list li');
            $.each(listitems,function(listitems,k){
                                j=$(k);
                                if(j.hasClass("has_children"))
                                    return 1;
                                j.unbind("click");
                            });
    }
14 Replies
Alessandro Cecconi

Hello,

Since I am not familiar with Java, I would like to have some information about the Javascript for restricted navigation in HTML5.

1- Do I have to put it into the "story.js" file? If yes, where?

2- Can I use it as it is (apart from the [name]  element in the first line)?

Thank you!

Alessandro

if (player.useCanvas) {

            // [name] is the name of the event "click", "mouseover", .. 

            // same as you'd pass it to bind()

            // [fn] is the handler function

            $.fn.bindFirst = function(name, fn) {

                // bind as you normally would

                // don't want to miss out on any jQuery magic

                this.bind(name, fn);

                // Thanks to a comment by @Martin, adding support for

                // namespaced events too.

                var handlers = this.data('events')[name.split('.')[0]];

                // take out the handler we just inserted from the end

                var handler = handlers.pop();

                // move it at the beginning

                handlers.splice(0, 0, handler);

            };

            listitems = $('#slide_list li');

            $.each(listitems,function(listitems,k){

                                j=$(k);

                                if(j.hasClass("has_children"))

                                    return 1;

                                j.bindFirst("click",function(event){if(!$(k).hasClass("visited"))event.stopImmediatePropagation();});

                            });

    }

Locked Navigation:
To 'Lock' the use of the Menu for navigation use the code below.
    if (player.useCanvas) {
            listitems = $('#slide_list li');
            $.each(listitems,function(listitems,k){
                                j=$(k);
                                if(j.hasClass("has_children"))
                                    return 1;
                                j.unbind("click");
                            });
    }
Jamie Smith

Hi Alessandro,

If you're mainly concerned with restricting the use of the Menu/Outline in HTML since it does not allow restriction or locking as does the Flash content you should use the code referenced above.

You can actually paste the code directly into a Javascript event/trigger on one of your slides. I've included an image below as guidance. You should use only one of the sample blocks of code provided in my initial post, either 'Restricted' or 'Locked' navigation.

Restricted will prohibit the user to navigate to a slide not yet viewed. The Locked will not allow use of the Menu/Outline at all for navigation. The example below uses the Restricted code.

You should create a new Javascript trigger on your slide. Typically this would be at start of timeline. Click on the 'Script' button as shown in the Trigger Wizard below, then insert the code provided. You can test by publishing with HTML5, then launch the story_html5.html file. You may need to use Internet Explorer for local testing since some browsers seem to block local execution of Javascript.

Jamie Smith

Sorry Alessandro. I must not have gotten the subscribe email on this as I just saw your post.

I think I see the problem. I referenced 'player' which would not be defined without a 'var player = GetPlayer();' prior to it. That's likely the issue. If you're unsure, I would recommend using the Javascript console in the developer tools in Chrome. You would view an error in this case.

So, once again, I'll post some code. Please let me know if you find success.

var player = GetPlayer();

if (player.useCanvas) {

            // [name] is the name of the event "click", "mouseover", .. 

            // same as you'd pass it to bind()

            // [fn] is the handler function

            $.fn.bindFirst = function(name, fn) {

                // bind as you normally would

                // don't want to miss out on any jQuery magic

                this.bind(name, fn);

                // Thanks to a comment by @Martin, adding support for

                // namespaced events too.

                var handlers = this.data('events')[name.split('.')[0]];

                // take out the handler we just inserted from the end

                var handler = handlers.pop();

                // move it at the beginning

                handlers.splice(0, 0, handler);

            };

            listitems = $('#slide_list li');

            $.each(listitems,function(listitems,k){

                                j=$(k);

                                if(j.hasClass("has_children"))

                                    return 1;

                                j.bindFirst("click",function(event){if(!$(k).hasClass("visited"))event.stopImmediatePropagation();});

                            });

}

Jamie Smith

Here's an updated and simpler version of the HTML5 restrict outline navigation method.

I've learned a bit about the player javascript since and this is a bit more efficient.

Place this on each slide at the beginning of the timeline or whenever you want to update the Outline. Running this on each slide will ensure that the list is updated to allow access to newly visited slide(s).

if (GetPlayer().useCanvas) {

     $.each($("ul.slidelist li"),function(i,k){

           !$(k).hasClass("has_children") && !$(k).hasClass("visited") && $(k).addClass("locked")

     });

}

Bob Mongiovi

Hi Ashley,

I prefer that it doesn't let you advance until the timeline ends.  But I noticed that after you have already viewed a slide and you go back to it via the menu or the back button, you still need to wait for the timeline to end to advance again.  Is there an option to set it up so that the next button is restricted on only the first time you watch that slide?  Or is that something that I should add as a request?

Thanks!

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