Here’s a bunch of news updates regarding the pipwerks SCORM JavaScript wrapper.

Time for class?

A big fad these days is object-oriented JavaScript; libraries such as jQuery and MooTools make it really easy to create JavaScript “classes” (in quotes because from what I can gather, they’re really JavaScript approximations of classes, but I’m no expert on programming semantics).

For a few months I was wondering if I should convert my JavaScript-based SCORM wrapper to a class format. The syntax would be easy enough to use: var scorm = new SCORM();, much like my SCORM ActionScript classes.

Last weekend I went ahead and converted the wrapper to a class just to see how I’d like it. Verdict: It’s kind of neat I guess, but it isn’t really an improvement over the SCORM “object” method I used in the first wrapper.

One of the benefits of using a class is that you can create multiple objects that inherit from the class, such as:

var bmw = new Car(); var toyota = new Car(); var volkswagen = new Car();
Code language: JavaScript (javascript)

But with SCORM, you really don’t want more than one SCORM object… it would totally kill the LMS communication. Scratch that perk.

Another perk of using classes is that you can ‘wrap’ all of your variables and functions into the class and keep the global namespace clean. Well, the object approach used in the first wrapper has the exact same number of global variables used in the class approach: one. Scratch that perk, too.

One of the perks of the object approach is that you’ll always know what your object’s name is; this is really important for getting my SCORM ActionScript classes to work with the SCORM JavaScript wrapper! The object name used in the wrapper (“SCORM”) is hard-coded into the ActionScript classes.

On the JavaScript side, if a class were used instead of the object, the name would be whatever the developer chooses, such as

var sco = new SCORM();
Code language: JavaScript (javascript)

or

var s = new SCORM();
Code language: JavaScript (javascript)

This means the ActionScript classes would need to be updated anytime the developer uses a different object name. Advantage: object approach.

So I guess I’ll stick to the object version. 🙂

Speaking of the object version…

I updated the wrapper to version 1.1.5. I haven’t uploaded it yet, because I still need to test it out. It passes JSLint, but I need to run it through my various SCORM tests to make sure it works OK.

Here is a quick list of changes & improvements.

Changed the global variable from SCORM to pipwerks

No, this isn’t vanity run amok, it’s a simple programming convention to prevent naming conflicts; the variable pipwerks is less likely to run into naming conflicts in an online course than a variable named SCORM. But, rest assured, if you prefer to use the variable SCORM, all you need to do is add this line at the top of your HTML file after you import the wrapper file:

var SCORM = pipwerks.SCORM;
Code language: JavaScript (javascript)

Easy! 🙂

New shortcuts

Added some shortcuts to make coding a little easier. Instead of

var success = pipwerks.SCORM.connection.initialize();
Code language: JavaScript (javascript)

you can do

var success = pipwerks.SCORM.init();
Code language: JavaScript (javascript)

Here are all of the shortcuts I added:

pipwerks.SCORM.init = pipwerks.SCORM.connection.initialize; pipwerks.SCORM.get = pipwerks.SCORM.data.get; pipwerks.SCORM.set = pipwerks.SCORM.data.set; pipwerks.SCORM.save = pipwerks.SCORM.data.save; pipwerks.SCORM.quit = pipwerks.SCORM.connection.terminate;

If you use the scorm renaming example I just showed you, your code could be as concise as this:

var sco = pipwerks.SCORM; sco.init(); sco.get("cmi.core.lesson_location"); sco.set("cmi.core.lesson_location", "http:pipwerks.com"); sco.save(); sco.quit();
Code language: JavaScript (javascript)

Nice and short, huh?

Relocated some functions

Now that the global namespace is pipwerks, I was able to move some non-SCORM stuff out of the SCORM object. Specifically, I moved SCORM.debug.displayInfo to pipwerks.UTILS.trace and SCORM.UTILS.StringToBoolean to pipwerks.UTILS.StringToBoolean. Small tweak, but it helps keep things tidy.

General clean-up

To make the code more concise (and shorter), I replaced the if SCORM 1.2 / else if SCORM 2004 statements with switch statements. They’re just as effective and take much less space.

I also cleaned up the commenting a bit in an effort to make it more readable.

Licensing change

I decided to change the copyright notice I had been using (Creative Commons) to the more widely supported MIT-style license. I’ll still be using Creative Commons licensing on my examples and other files, but for pure code-stuff, the MIT-style license will probably work best for most people.

Similar Posts