Documentation

Player services

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

PlayerServices type

Function Description
getPresentation() Returns the object that represents the presentation. This object implements several functions related to accessing the presentation and its pages.
getCurrentPageIndex() Returns the current page index (0-based).
getCommands() Returns the object that implements different commands you can call from your addon.
getEventBus() Returns the object that implements the event bus.
getScore() Returns the object that 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 the book mode (shows 2 pages).
hasCover() Returns true if the first page is always shown as a single page.
getTimeService() Returns the object that represents TimeService.
getScaleInformation() Returns the object that represents ScaleInformation. It provides data necessary to account for scaling on mobile devices.
getObserverService() Returns the object that represents ObserverService. It allows notifying the embedding page that it should commence save of the score and the state of the lesson.
getResponsiveLayouts() Returns the object which contains lesson layouts.

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's ID.
getName() Returns the page's name.
getBaseURL() Returns the page's base URL with a slash '/' at the end.
isReportable() Returns true if the page's contents are to be included in the lesson report.
isVisited() Returns true if a page has been visited.
getModules() Returns a list of IDs of all modules on the page.
isNotAssignable() Returns true if the page is not assignable.

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(updateCounters) Sets the presentation to showErrorsMode. updateCounter is an optional boolean argument (defaults to 'true') that determines whether calling this method will increase the check counter and the mistakes counter.
uncheckAnswers() Restores the presentation to workMode.
sendPageAllOkOnValueChanged(boolean) Sets the player to send the PageAllOK event on every ValueChanged event occurrence. 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 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, layoutName) Outstretch the page height from point y by the value of height. To change page height without moving the modules, set dontMoveModules parameter to true. To change page height for one layout only, pass its name to the layoutName parameter.

EventBus

Function Description
addEventListener(event_name, listener) Registers the listener for a specific event. The listener is the object that 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 a hashmap with values:
  • score - actual score
  • maxScore - max page score
  • checkCount - how many times the check button has been selected on this page
  • mistakeCount - the total number of shown errors
getPageScoreById(pageId) Returns score for a given page. The score is a hashmap with values:
  • score - actual score
  • maxScore - max page score
  • checkCount - how many times the check button has been selected on this page
  • mistakeCount - the total number of shown errors
  • time - the total time spent on this page
getOpenActivityScores(pageId, moduleId) Returns the 'Open Activity's' score for the given page's module. The score is a hashmap with values:
  • aiGradedScore - score granted by AI. If the score is not granted, return null.
  • manualGradedScore - score granted by Teacher. If the score is not granted, return null.
  • aiRelevance - AI's evaluation component determines the relevance between the input data and the expected outcome. If relevance is not granted, it returns null.
  • maxScore - max score. If the addon is not an open activity (addon with set Manual Grading) or belongs to the not visited page, it returns null.
A hashmap is always returned regardless of whether the module is supported by the Open Activity and if it has received any scores from the Open Activity.

TextParser

Function Description
parse(text) Parses the given text and replaces the definition \def{word} with links.
parseGaps(text, options) Parses the 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 the 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 milliseconds.
getPageTimeById(pageId) Returns a string that is the total time spent on the lesson's page with the given ID (in milliseconds).

ScaleInformation type

The Scale Information type shown in this section refers to the object that is returned using the getScaleInformation command. Learn more about scale information by visiting the Scale Information section.

Field Description
baseScaleX Scaling of the player on the X axis. It is equal to the actual displayed width of the player by its width without scaling. The default value is 1.0.
baseScaleY Scaling of the player on the Y axis. It is equal to the actual displayed height of the player by its height without scaling. The default value is 1.0.
scaleX Scaling of the page ('.ic_page' element) on the X axis. It is equal to the baseScaleX value multiplied by the modifier applied by one of the addons. The default value is 1.0.
scaleY Scaling of the page ('.ic_page' element) on the Y axis. It is equal to the baseScaleY value multiplied by the modifier applied by one of the addons. The default value is 1.0.
transform Value of transform CSS style applied to the player. The default value is "".
transformOrigin Value of transform-origin CSS style applied to the player. The default value is "".

ObserverService type

Function Description
addObserver(type: ObserverType, callbackObject: ICallbackObject) Adds observer of a specified type. ObserverType is a string type. Allowed values are: "save". ICallbackObject is an interface of the following structure: { next: () => {}; }
notifySave() Calls all observers of "save" type.