JClicPlayer. JClicPlayer

JClicPlayer is one of the the main classes of the JClic system. It implements the
PlayStation
interface, needed to host JClic activities.
JClicPlayer offers to ActivityPanel objects all the necessary resources and functions:
media bags (to load and realize images and other media contents), sequence control, management
of the reporting system, user interface, display of system messages, etc.

Constructor

new JClicPlayer($topDiv, optionsopt)

JClicPlayer constructor

Parameters:
NameTypeAttributesDescription
$topDivexternal:jQuery

The HTML div element where this JClicPlayer will deploy.

optionsobject<optional>

A set of optional customized options.

Extends

Members

$div :external:jQuery

The JQuery "div" element used by this player as stage for activities

$mainContainer :external:jQuery

The main container of all JClic components

$topDiv :external:jQuery

The JQuery top container where this player will deploy

actPanel :module:Activity.Activity#Panel

The ActivityPanel currently running on this player.

Type:
  • module:Activity.Activity#Panel

actions :Array.<module:AWT.Action>

Collection of module:AWT.Action objects used by this player.

Type:

activeMediaBag :module:media/ActiveMediaBag.ActiveMediaBag

Object containing references to realized media objects, ready to play.

audioEnabled :boolean

Whether the player must play all sounds (including system sounds) and other media content
of the activities.

Type:
  • boolean

basePath :string

Relative path or absolute URL to be used as a base to access files

Type:
  • string

bgImageOrigin :module:AWT.Point

Point indicating the upper-left corner of the current background image

counterVal :module:JClicPlayer.JClicPlayer~counterValType

Current values of the counters

Type:
  • module:JClicPlayer.JClicPlayer~counterValType

defaultSkin :module:skins/Skin.Skin

The default Skin to be used if none specified

defaultSkin :module:skins/Skin.Skin

The last skin directly specified by a JClicProject

delayedAction :module:AWT.Action

This variable holds the action to be executed by delayedTimer

delayedTimer :module:AWT.Timer

Timer for delayed actions

dim :module:AWT.Dimension

The Dimension of the Rectangle

fullScreenChecked :boolean

Flag indicatig that this player has switched to full screen at least once

Type:
  • boolean

history :module:PlayerHistory.PlayerHistory

This object records the list of the activities played during the current session.

id :string

Unique ID of this player, randomly generated by the constructor

Type:
  • string

invalidatedRect :module:AWT.Rectangle

The currently "invalidated" area

localFS :boolean

This flag indicates if the player is running inside a document loaded by file: protocol

Type:
  • boolean

When this flag is true, the navigation buttons are always enabled despite
of the indications made by the activities or the sequence control system.
This is used only to debug projects with complicated sequence chaining.

Type:
  • boolean

Whether the navigation buttons next and back are enabled o disabled.

Type:
  • boolean

options :object

Object with miscellaneous options.

Type:
  • object

pos :module:AWT.Point

The current position of the shape

project :module:project/JClicProject.JClicProject

The JClicProject currently hosted in this player

reporter :module:report/Reporter.Reporter

Object responsible for passing the scores obtained by users to a external reporting systems
when playing activities.

skin :module:skins/Skin.Skin

The Skin currently used by this player.

timer :module:AWT.Timer

Main timer object used to feed the time counter. Ticks every second.

type :string

Shape type id

Type:
  • string

zip :external:JSZip

A external:JSZip object pointing to a jclic.zip or jclic.scorm.zip file containing
the current project.
Two extra properties will be added to this object when loaded:

  • zip.fullZipPath {string} - The full path of the ZIP file
  • zip.zipBasePath {string} - The path to the folder containing the ZIP file

Methods

activityFinished(_completedOK)

Called from Activity when finished.

Parameters:
NameTypeDescription
_completedOKboolean

true when the activity was successfully completed, false
otherwise.

activityReady()

Called by module:JClicPlayer.JClicPlayer#load when the ActivityPanel is fully visible, just
after the JQuery animation effect.

add(shape) → {module:AWT.Rectangle}

Adds the boundaries of another shape to the current one

Parameters:
NameTypeDescription
shapemodule:AWT.Shape

The module:AWT.Shape to be added

Returns:
Type: 
module:AWT.Rectangle

buildActions()

Builds the module:AWT.Action objects for this player

clip(ctx, fillRuleopt) → {external:CanvasRenderingContext2D}

Creates a clipping region on the specified HTML canvas 2D rendering context

Parameters:
NameTypeAttributesDefaultDescription
ctxexternal:CanvasRenderingContext2D

The rendering context

fillRulestring<optional>
'nonzero'

Can be 'nonzero' (default when not set) or 'evenodd'

Returns:
  • The provided rendering context
Type: 
external:CanvasRenderingContext2D

clone() → {module:AWT.Rectangle}

Clones this Rectangle

Returns:
Type: 
module:AWT.Rectangle

closeHelpWindow()

Closes the help dialog window

contains(_p) → {boolean}

Checks if the provided module:AWT.Point is inside this shape.

Parameters:
NameTypeDescription
_pmodule:AWT.Point

The point to check

Returns:
Type: 
boolean

displayURL(url, inFrame)

Navigates to the requested URL

Parameters:
NameTypeDescription
urlstring

The URL to navigate to

inFrameboolean

When true opens in a new frame

doLayout()

Configures the layout and visual aspect of the player area.

end() → {external:Promise}

Executes miscellaneous finalization routines.

Returns:
  • A promise to be fullfilled when all pending tasks are finished.
Type: 
external:Promise

equals(r) → {boolean}

Checks if two shapes are equivalent.

Parameters:
NameTypeDescription
rmodule:AWT.Shape

The Shape to compare against

Returns:
Type: 
boolean

exit(url)

Only when exitUrl has been specified in options, navigates to the specified URL

Parameters:
NameTypeDescription
urlstring

The URL to navigate to.

fill(ctx, dirtyRegionopt) → {external:CanvasRenderingContext2D}

Fills the Shape with the current style in the provided HTML canvas context

Parameters:
NameTypeAttributesDescription
ctxexternal:CanvasRenderingContext2D

The canvas 2D rendering context where to fill this shape.

dirtyRegionmodule:AWT.Rectangle<optional>

The context region to be updated. Used as clipping
region when drawing.

Returns:
  • The provided rendering context
Type: 
external:CanvasRenderingContext2D

forceFinishActivity()

Forces the current activity to stop playing.

getActiveMediaPlayer(mediaContent) → {module:media/ActiveMediaPlayer.ActiveMediaPlayer}

Parameters:
NameTypeDescription
mediaContentmodule:media/MediaContent.MediaContent

The media content to be played

getAttributes() → {object}

Gets a object with the basic attributes needed to rebuild this instance excluding functions,
parent references, constants and also attributes retaining the default value.
The resulting object is commonly usued to serialize elements in JSON format.

Returns:
  • The resulting object, with minimal attrributes
Type: 
object

getBounds() → {module:AWT.Rectangle}

Gets the enclosing Rectangle of this Shape.

Returns:
Type: 
module:AWT.Rectangle

getCoords() → {string}

Gets a string with the co-ordinates of the upper-left and lower-right vertexs of this rectangle,
(with values rounded to int)

Returns:
Type: 
string

getCounterValue(counter) → {number}

Gets the current value for the specified counter

Parameters:
NameTypeDescription
counterstring

The id of the counter ('score', 'actions' or 'time')

Returns:
Type: 
number

getOppositeVertex() → {module:AWT.Point}

Gets the module:AWT.Point corresponding to the lower-right vertex of the Rectangle.

Returns:
Type: 
module:AWT.Point

getShape(rect) → {module:AWT.Shape}

Gets a clone of this shape moved to the pos component of the rectangle and scaled
by its dim value.

Parameters:
NameTypeDescription
rectmodule:AWT.Rectangle

The rectangle to be taken as a base for moving and scaling
this shape.

Returns:
Type: 
module:AWT.Shape

getUniqueId(lb) → {string}

Generates an unique ID for elements being used with this player

Parameters:
NameTypeDescription
lbstring

The element's label

Returns:
Type: 
string

grow(dx, dy) → {module:AWT.Rectangle}

Expands the boundaries of this shape. This affects the current position and dimension.

Parameters:
NameTypeDescription
dxnumber

The amount to grow (or decrease) in horizontal direction

dynumber

The amount to grow (or decrease) in vertical direction

Returns:
Type: 
module:AWT.Rectangle

incCounterValue(counter)

Increments by 1 the value of the specified counter

Parameters:
NameTypeDescription
counterstring

The id of the counter ('score', 'actions' or 'time')

incProgress(valopt)

Increments the progress bar value by the specified amount, only when the progress bar is running.

Parameters:
NameTypeAttributesDefaultDescription
valnumber<optional>
1

The amount to increment. When not defined, it's 1.

initActivity()

Initializes the activity

initReporter() → {external:Promise}

Creates and initializes the Reporter member

Returns:
Type: 
external:Promise

initTimers()

Creates and initializes objects of type module:AWT.Timer

intersects(_r) → {boolean}

Checks if the provided Rectangle r intersects with this shape.

Parameters:
NameTypeDescription
_rmodule:AWT.Rectangle
Returns:
Type: 
boolean

invalidate(rect)

Adds the provided rectangle to the invalidated area.

Parameters:
NameTypeDescription
rectmodule:AWT.Rectangle

isRect() → {boolean}

Shorthand method for determining if a Shape is an Rectangle

Returns:
Type: 
boolean

listenTouchEvents()

Detects swipe-right, swipe-left and double touch gestures on touch devices,
associating them with 'next activity', 'previous activity' and 'toggle full screen' actions

load(projectopt, sequenceopt, activityopt)

Loads the specified project and starts playing at the specified activity or sequence tag.

Parameters:
NameTypeAttributesDescription
projectstring | JClicProject<optional>

The project to load (if it's a string) or to use (if it's an object of type JClicProject).
When it's a string, it can be the absolute or relative path to:

  • A .jclic project file, in XML format
  • A .jclic.json project file in JSON format
  • A .jclic.zip compressed project file (containing one file of type '.jclic' or '.jclic.json')
  • A .scorm.zip file, as exported by JClic Author.
  • A project.json file, as exported by JClic Author
    When null or undefined, refers to the current project.
sequencestring | number<optional>

Sequence tag or numeric order in the ActivitySequence
to be loaded. If sequence and activity are both null, the first ActivitySequenceElement
will be loaded.

activitystring<optional>

Name of the activity to be loaded (usually null)

moveBy(delta) → {module:AWT.Shape}

Shifts the shape a specified amount in horizontal and vertical directions

Parameters:
NameTypeDescription
deltaPoint | Dimension

The amount to shift the Shape

Returns:
Type: 
module:AWT.Shape

moveTo(newPos) → {module:AWT.Shape}

Moves this shape to a new position

Parameters:
NameTypeDescription
newPosmodule:AWT.Point

The new position of the shape

Returns:
Type: 
module:AWT.Shape

playMedia(mediaContent, mediaPlacementopt, delayedActionsopt)

Plays the specified media.

Parameters:
NameTypeAttributesDefaultDescription
mediaContentmodule:media/MediaContent.MediaContent

The media to be played

mediaPlacementmodule:boxes/ActiveBox.ActiveBox<optional>
null

The cell where the graphic component of this media should be placed (used with video objects)

delayedActionsArray.<function()><optional>
null

If set, store the the action in this array for future execution

playMsg()

Launches the active media content associated to the main message, if any.

preparePath(ctx) → {external:CanvasRenderingContext2D}

Prepares an HTML canvas 2D rendering context with a path that can be used to stroke a line,
to fill a surface or to define a clipping region.

Parameters:
NameTypeDescription
ctxexternal:CanvasRenderingContext2D
Returns:
  • The provided rendering context
Type: 
external:CanvasRenderingContext2D

removeActivity()

Removes the current ActivityPanel from this player

reportEndActivity(act, solved)

Notifies the reporting system that the current activity has finished

Parameters:
NameTypeDescription
actmodule:Activity.Activity

The activity that is sending the notification

solvedboolean

Whether the activity was successfully completed or not.

reportNewAction(act, type, source, dest, ok, currentScore)

Notifies the reporting system that a new action has been performed on the current activity

Parameters:
NameTypeDescription
actmodule:Activity.Activity

The activity that is sending the notification

typestring

Type of action (match, move, switch...)

sourcestring

Object acting as a source of the action (cell, grid, clue...)

deststring

When applicable, object acting as a receiver of the action (cell, grid...)

okboolean

Whether the action was OK or not

currentScorenumber

The current score of the activity

reportNewActivity(act)

Notifies the reporting system that a new activity has started

Parameters:
NameTypeDescription
actmodule:Activity.Activity

The activity that is sending the notification

reset()

Resets the main components of this player

runCmd(cmd)

Launches the specified system command.
Currently not implemented.

Parameters:
NameTypeDescription
cmdstring

scaleBy(delta) → {module:AWT.Rectangle}

Multiplies the dimension of the Shape by the specified delta amount.

Parameters:
NameTypeDescription
deltaPoint | Dimension

Object containing the X and Y ratio to be scaled.

Returns:
Type: 
module:AWT.Rectangle

setAttributes(data) → {module:AWT.Rectangle}

Reads the properties of this Rectangle from a data object

Parameters:
NameTypeDescription
dataobject

The data object to be parsed

Returns:
Type: 
module:AWT.Rectangle

setBounds(rect) → {module:AWT.Rectangle}

Sets this Rectangle the position and dimension of another one

Parameters:
NameTypeDescription
rectmodule:AWT.Rectangle
Returns:
Type: 
module:AWT.Rectangle

setCountDown(counter, maxValue)

Sets the specified counter in count-down status, starting at maxValue.

Parameters:
NameTypeDescription
counterstring

The id of the counter ('score', 'actions' or 'time')

maxValuenumber

The value from which to start counting down

setCounterEnabled(counter, bEnabled)

Enables or disables a specific counter

Parameters:
NameTypeDescription
counterstring

The id of the counter ('score', 'actions' or 'time')

bEnabledboolean

When true, the counter will be enabled.

setCounterValue(counter, newValue)

Sets a value to the specified counter

Parameters:
NameTypeDescription
counterstring

The id of the counter ('score', 'actions' or 'time')

newValuenumber

The value to be set

setMsg(abc)

Sets the current main message.

Parameters:
NameTypeDescription
abcmodule:boxes/ActiveBoxContent.ActiveBoxContent

The content of the message

setProgress(val, maxopt)

Sets the current value of the progress bar

Parameters:
NameTypeAttributesDescription
valnumber

The current value. Should be less or equal than max. When -1, the progress bar will be hidden.

maxnumber<optional>

Optional parameter representing the maximum value. When passed, the progress bar will be displayed.

setProject(project)

Sets the current project of this player, without starting any activity

Parameters:
NameTypeDescription
projectmodule:project/JClicProject.JClicProject

The project to be set

setSkin(newSkinopt)

Sets the current skin

Parameters:
NameTypeAttributesDescription
newSkinmodule:skins/Skin.Skin<optional>

The skin to use. When null, defaultSkin will be used.

setWaitCursor(status)

Set/unset the panel in 'wait' state

Parameters:
NameTypeDescription
statusboolean

setWindowTitle(docTitle)

Sets a title in a specific HTML element, if provided.

Parameters:
NameTypeDescription
docTitlestring

showHelp($hlpComponent) → {boolean}

Shows the help info provided by the activity

Parameters:
NameTypeDescription
$hlpComponentexternal:jQuery

The jQuery DOM component to be shown.

Returns:
  • True when the component was successfully displayed
Type: 
boolean

showReports()

Opens the reports dialog

startActivity()

Starts the activity. This method is usually called from text activities with previous text.

startAutoPassTimer()

Starts the automatic jump to next activity, when applicable.

stop()

Instructs the player to stop working

stopMedia(levelopt)

Stops currently playing media

Parameters:
NameTypeAttributesDefaultDescription
levelnumber<optional>
-1

Sets the threshold above which all media objects with equal
or greater level will also also be muted.

stroke(ctx) → {external:CanvasRenderingContext2D}

Draws this shape in the provided HTML canvas 2D rendering context.

Parameters:
NameTypeDescription
ctxexternal:CanvasRenderingContext2D

The canvas 2D rendering context where to draw the shape.

Returns:
  • The provided rendering context
Type: 
external:CanvasRenderingContext2D

toString() → {string}

Overwrites the original 'Object.toString' method with a more descriptive text

Returns:
Type: 
string

update()

Updates the invalidated area

updateContent(_dirtyRegion)

Containers should implement this method to update its graphic contents. It should
be called from module:AWT.Container#update

Parameters:
NameTypeDescription
_dirtyRegionmodule:AWT.Shape

Specifies the area to be updated. When null, it's the whole
Container.