PlayerServices can be used to call a function on a player runtime.
PlayerServices type
Function |
Description |
getPresentation() |
Returns the object that 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 that implements different commands you can call from your addon. |
getEventBus() |
Returns the object which implements 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 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 that represents ScaleInformation. It provides data necessary to account for scaling on mobile devices. |
getObserverService() |
Returns the object that represents ObserverService. It allows to notify the embedded page that it should commence save of the score and the state of the lesson. |
getResponsiveLayouts() |
Returns the object which contains lesson layouts. |
getRequestsConfig() |
Returns an object whose functions allow to get information from the setup of content delivery with licensing. |
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 a 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 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 – a 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 – 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 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.
A hashmap is always returned regardless of whether 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 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 of 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 the 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.
|
RequestsConfig type
The Requests Config type shown in this section refers to the set of methods that can be used by private addons to adjust them to solutions for content delivery with licensing. Values returned by these methods relate to the information provided
in the player setup for this solution.
In rare cases, for private addons to work with that solution, they must obtain and then use some of this information.
In most cases, changes to private addons do not need to be made, as the player should provide appropriately modified
URLs (e.g. URLs from addons properties) for private addons.
Function |
Description |
shouldIncludeCredentials() |
Returns true if the player is in an environment that requires requests (from e.g., fetch API) for resources to include credentials
(Signing cookie).
|
getSigningPrefix() |
Returns signing prefix that the player uses to request resources. If the signing prefix was not provided to the player, then this method returns null.
Please do not use the returned value to sign URLs. This method was created to verify that the environment provides a signing prefix.
|
signURL(url) |
Returns signed URL with prefix returned from the getSigningPrefix method. If the signing prefix was not provided to the player or the given URL does not need signing, then this method returns an unchanged URL.
|