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 (0-based). |
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. |
getObserverService() |
Returns the object which represents ObserverService. It allows to notify embeding 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 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 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 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, layoutName) |
Outstretch the page height from point y by the value of height. To change page height without moving 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 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
|
getOpenActivityScores(pageId, moduleId) |
Returns `Open Activity`' score for a given page's module. The score is hashmap with values:
- aiGradedScore – score granted by AI. If score is not granded, return null.
- manualGradedScore – score granted by Teacher. If score is not granded, return null.
A hashmap is always returned regardless of if a module is supported by Open Activity and if it has received any scores from Open Activity.
|
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
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 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 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 specified type.
ObserverType is a string type. Allowed values are: "save".
ICallbackObject is an interface of following strucutre:
{
next: () => {};
}
|
notifySave() |
Calls all observers of "save" type.
|