Documentation

Player services

PlayerServices can be used to call a function on a player runtime.

PlayerServices type

Function Description
getPresentation() Returns the object which represents a presentation. This object implements several functions related to accessing the presentation and its pages.
getCurrentPageIndex() Returns the current page index.
getCommands() Returns the object which implements different commands you can call from your addon.
getEventBus() Returns the object which implements event bus.
getScore() Returns the object which implements commands for accessing the player score.
getModule(moduleID) Returns the module presenter based on the given ID.
getHeaderModule(moduleID) Returns the module presenter based on the given ID from the header page.
getFooterModule(moduleID) Returns the module presenter based on a given ID from the footer page.
getTextParser() Returns the object which is a parser for text elements like definition links.
getStaticFilesPath() Returns the path to static files included with the player.
getAssets() Returns the object which implements the assets' command:
  • getContentType(href) - returns the content type of a given asset
isBook() Returns true if the player is in a book mode (shows 2 pages).
hasCover() Returns true if the first page is always shown as a single page.
getTimeService() Returns the object which represents TimeService.
getScaleInformation() Returns the object which represents ScaleInformation. It provides data necessary to account for scaling on mobile devices.

Presentation type

Function Description
getPageCount() Returns the number of pages.
getPage(index) Returns the page at a given index.
getPageById(id) Returns the page with a given id.
getTableOfContents() Returns the hierarchical table of contents which consists of Chapters and Pages. The chapter has the following methods:
  • type - "chapter"
  • getName() - Chapter name
  • size() - number of chapter nodes
  • get(index) - get node (Chapter or Page)
The page has the following methods:
  • type - "page"
  • getName() - Page name
  • getBaseURL() - URL base
  • isReportable() - Returns true if page is reportable

Page type

Function Description
getId() Returns the page id.
getName() Returns the page name.
getBaseURL() Returns the page base URL with slash '/' at the end.
isReportable() Returns true if the page contents are to be included in a lesson report.
isVisited() Returns true if a page has been visited.
getModules() Returns a ist of ids of all modules on the page.

Commands type

Function Description
executeEventCode(code) Sends the script code to be executed by the player.
gotoPage(name) (depreciated) Go to the page with a given name.
gotoPageIndex(index) Go to the page at a given index.
gotoPageId(id) Go to the page with a given ID.
getTimeElapsed() Returns time in seconds elapsed from the start of the lesson session.
checkAnswers() Sets the presentation to showErrorsMode.
uncheckAnswers() Restores the presentation to workMode.
sendPageAllOkOnValueChanged(boolean) Sets the player to send the PageAllOK event on every ValueChanged event occurence. This causes the player to calculate the score after each event so it should be used with caution (it may alter your final score)!
setNavigationPanelsAutomaticAppearance(boolean) Sets whether navigation panels should appear / hide after clicking on the inactive lesson's area. The default behavior is true.
showNavigationPanels() Shows navigation panels.
Note: to show the page navigation you have to define proper CSS styles.
hideNavigationPanels() Hides navigation panels.
showPopup(pageName, top, left) Shows the popup page with a given page name and optionally with a given top and left position.
closePopup() Closes the popup page.
outstretchHeight(y, height, dontMoveModules) Outstretch the page height from point y by the value of height. To change page height without moving modules, set dontMoveModules parameter to true.

EventBus

Function Description
addEventListener(event_name, listener) Registers the listener for a specific event. The listener is the object which implements: onEventReceived(eventName, eventData) function.
  • eventName – event name
  • eventData – an array with event data
sendEvent('ItemSelected', data); Send event
  • eventName – event name
  • eventData – an array with event data

Score

Function Description
getMaxScore() Returns max score for the whole presentation.
getTotalScore() Returns score calculated for all opened pages.
getPageScore(pageName) (depreciated) Returns score for a given page. The score is hashmap with values:
  • score – actual score
  • maxScore – max page score
  • checkCount – how many times the check button has been selected on this page
  • mistakeCount – a total number of shown errors
getPageScoreById(pageId) Returns score for a given page. The score is hashmap with values:
  • score – actual score
  • maxScore – max page score
  • checkCount – how many times the check button has been selected on this page
  • mistakeCount – a total number of shown errors
  • time – the total time spent on this page

TextParser

Function Description
parse(text) Parses a given text and replaces the definition \def{word} with links.
parseGaps(text, options) Parses a given text and replaces it with a gap HTML code. Options include a JavaScript object (isCaseSensitive is the only option available at this moment).
connectLinks(element); Connects all definition links to event bus. Each link will send the Definition event.

TimeService type

Function Description
getTotalTime() Returns a string that is the total time spent in the lesson in miliseconds.
getPageTimeById(pageId) Returns a string that is the total time spent on the lesson's page of the given ID (in miliseconds).

ScaleInformation type

Field Description
scaleX Scaling of the player on the X axis. It is obtained by dividing the actual displayed width of the player by its width according to the width property. The default value is 1.0 .
scaleY Scaling of the player on the Y axis. It is obtained by dividing the actual displayed height of the player by its height according to the height property. The default value is 1.0 .
transform Value of transform css style applied to the player during resizing. The default value is "".
transformOrigin Value of transform-origin css style applied to the player during resizing. The default value is "".