Pseudocode API

The pseudocode API in JSAV is intended for showing a static set of codelines that can be show/hidden and highlighted. There are two ways to initialize a pseudocode object in JSAV:

.code(codelines[, options]) or .code([options])

Both of these are functions of a JSAV object instance. The first version takes either an array or a string to be used as the lines of code. If a string is passed, it will be split on newline characters (\n) to get the codelines.

The options that can be specified:

Pseudocode objects have the following functions.

.highlight(indices) and .unhighlight(indices)

Highlight and unhighlight the codelines at given indices. Lines are numbered from 0, so first line could be highlighted with:

pseudo.highlight(0)

Similarly to the array (un)highlight, the indices parameter can be either a number, an array of numbers, a function or a tag (see tags in options).

.show() and .hide()

Show/hide the pseudocode object.

.show(indices) and .hide(indices)

Show/hide the codelines at given indices. Again, indices can be a number, an array of numbers, a function or a tag.

.css(indices, css)

Apply the given CSS properties to the codelines at specified indices. Parameter indices can be a number, array, function or a tag like for the highlight method. The argument css should be an object with property name-and-value pairs. For example, to make lines 0 and 4 have green color and lightgray background:

pseudo.css([0, 4], {"color": "green", "background-color": "#eee"});

.setCurrentLine(index)

Sets the line at given index as the current line. Also, if another line was previously set as current, it will be marked as previous. If a line was also earlier marked as previous, that mark will be removed. This will help in creating a visual debugger-like code stepping functionality in visualizations. You can clear the current line selection with index value 0.

.clear()

Removes the DOM element of this object from the document. This is useful, for example, in re-initializing exercises when the existing object needs to be removed.

.addClass(indices, className, [options])

Adds the CSS class className to lines at given indices and animates the changes. Like for the rest of pseudocode methods, indices can be a number, array of numbers, a function or a tag.

.removeClass(indices, className, [options])

Removes the CSS class className from lines at given indices and animates the changes. Like for the rest of pseudocode methods, indices can be a number, array of numbers, a function or a tag.

.toggleClass(indices, className, [options])

Toggles the CSS class className of lines at given indices and animates the changes. Like for the rest of pseudocode methods, indices can be a number, array of numbers, a function or a tag.

.hasClass(index, className, [options])

Return true/false based on if the line at given index has the CSS class className. Parameter index should be a number or a tag to a number.