August 23, 2019
How to Create a 5-Star Rating System in Adobe Captivate
Comments
(8)
August 23, 2019
How to Create a 5-Star Rating System in Adobe Captivate
I have worked in the eLearning industry for over 15 years. I enjoy making tools/applications/web apps do things they were not meant to do. I have launched several tools to help develop better eLearning. CoursePortfolios.com: Explore demos from the world's best eLearning designers and developers. Where the most creative eLearning professionals share demos of their craft. ReviewMyElearning.com :  The is the best way to collect feedback from SMEs, Team Members, Clients, etc. Plus it's all in the cloud. I use my skills to create custom solutions for Web, Mobile, and Desktop. Primarily in the eLearning arena but we provide solutions for many other industries.
Newbie 17 posts
Followers: 44 people
(8)

SVGs are fun. Scalable Vector Graphics are really just fancy XML files. And this means we can use JavaScript to manipulate them. Which opens up a lot of possibilities. 

Before we get too far into this, take a moment to play with the demo:

LIVE DEMO

I was looking for a way to create a rating system that allowed learners to rate slides on a scale of 1-5. I am sure there are ways to build this within Captivate but I have this weird problem that makes me seek out alternative methods. And these usually involve JavaScript. 

What I wanted was a solution that would allow learners to click on a set of stars to indicate their opinion. That would then be aggregated with all the other learners’ selection. But I also wanted a smooth animation during the selection and when the average was updated. 

My solution ended up using an SVG file (with a mask), Captivate variables, and some JavaScript. 

To begin a created an SVG file that contains two boxes, black and gold. It also has a ‘mask’ that consists of five star shaped paths. 

Then I dropped my SVG into Captivate and created a couple of variables to track and display the learner’s rating and the average rating. 

Now it’s time for some JavaScript! I tend to solve these types of puzzles in stages. First I wanted to make sure that I could find the SVG within Captivate and resize the black box (under the mask). 

var obj = $("#stars_democ_object")[0];
var svgdoc = obj.getSVGDocument();
var box = svgdoc.getElementById("box");
var rating = window.cpAPIInterface.getVariableValue("Text_Entry_Box_1");
$(box).animate({ width: rating * 20 + "%" });

Let’s break that down:

  1. Find the HTML element that holds our SVG. 
  2. Get the SVG document 
  3. Get the black box inside our SVG
  4. Get the rating the learner entered. 
  5. Animate the width of the black box to the percentage indicated by the learner. 

That works pretty well! Now let’s add some mouse over animations. 

var user_stars_obj = $("#stars_user_ratingc_object")[0];
var user_stars_svgdoc = user_stars_obj.getSVGDocument();
var user_stars_box = user_stars_svgdoc.getElementById("box");
var ratio = 0;
$("#stars_user_rating").mousemove(function(event) {
ratio = Math.round((event.offsetX / $("#stars_user_rating").width()) * 100);
window.cpAPIInterface.setVariableValue("var_user_rating", ratio);
user_stars_box.setAttribute("width", ratio + "%");
});
$("#stars_user_rating").mousedown(function() {
$("#stars_user_rating").off("mousemove");
$("#stars_user_rating").off("mousedown");
});

This starts the same as the previous code. We get all our data and elements. 

Then we add two listeners to the DIV element (that contains the SVG). One to listen for the mouse moving over it. The other listens for mouse clicks on it. 

When the mouse moves over the SVG we get it’s position and set our black box’s width to match it. Note I did not bother to animate this since it follows the mouse movement. We also push the value back into our Captivate variable so we can display it. 

I will spare you the finished code. But you can grab it here

Watch the video to learn more about the final solution.

 

8 Comments
2021-06-04 20:48:37
2021-06-04 20:48:37

“I am sure there are ways to build this within Captivate but I have this weird problem that makes me seek out alternative methods. And these usually involve JavaScript.”

Ha ha, Amen to that.

Very cool idea; thanks for sharing!

Like
2020-09-23 08:10:23
2020-09-23 08:10:23

Useful

Like
2019-09-30 11:49:29
2019-09-30 11:49:29

Wow! That was nice. A while ago I was thinking about how to go about a similar thing. Now I have it. Thank you !

Like
2019-08-30 05:25:32
2019-08-30 05:25:32

 

Hello James

Good work

Did you used Inkscape for svg?

Luis

Like
(1)
>
luisr61870762
's comment
2019-09-01 11:44:04
2019-09-01 11:44:04
>
luisr61870762
's comment

Thanks!

I have used Inkscape in the past. But for this project I started with an existing SVG of five stars and edited the XML directly with VS Code.

Like
(2)
2019-08-29 21:47:34
2019-08-29 21:47:34

Gosh that looks great!  You’re lightyears ahead of where I am with JS – this definitely gives me good incentive to learn more.

Like
(1)
(2)
>
cynthiam85831266
's comment
2019-09-01 11:46:33
2019-09-01 11:46:33
>
cynthiam85831266
's comment

Well I probably know more JS then is actually useful in most eLearning careers. I just happen to specialize in this niche; helping developers/clients find crazy solutions for impossible puzzles 🙂

Like
(1)
>
James Kingsley
's comment
2020-02-27 12:52:01
2020-02-27 12:52:01
>
James Kingsley
's comment

I got interested in javascript. It gives you so many possibilities. And it’s a useful skill on it’s own.

Like
Add Comment