Skip to content

Module: src/text/SubtitlesUi

UI component for subtitle selection and font size control. Keeps presentation separated from the subtitle engine and talks via events.

Version
1.0.0
Author
Frank Kudermann - alphanull
License
MIT
Requires
Menu
Source
SubtitlesUi.js, line 12

Constructor

new SubtitlesUi(player, parent, optionsopt)

Creates an instance of the Subtitles UI component.

Parameters:
Name Type Attributes Description
player Player

Reference to the media player instance.

parent Popup

Reference to the parent instance (popup).

options Object optional

Additional options.

Parameters:
Name Type Attributes Description
apiKey symbol optional

Token for extended access to the player API.

Members

UI-related configuration derived from the subtitles config.

Type
Object
Source
SubtitlesUi.js, line 18

Reference to the main player instance.

Type
Player
Source
SubtitlesUi.js, line 29

Reference to the parent popup/controller.

Type
Object
Source
SubtitlesUi.js, line 35

Secret key only known to the player instance and initialized components.

Type
symbol
Source
SubtitlesUi.js, line 41

Reference to the font size menu (optional).

Type
Menu
Source
SubtitlesUi.js, line 53

Available subtitle tracks (without the "off" entry).

Type
Array
Source
SubtitlesUi.js, line 59

Currently active subtitle index (-1 for off).

Type
number
Source
SubtitlesUi.js, line 65

Allowed font sizes.

Type
Array<string>
Source
SubtitlesUi.js, line 71

Current font size.

Type
string
Source
SubtitlesUi.js, line 77

Holds tokens of subscriptions to player events, for later unsubscribe.

Type
Array<number>
Source
SubtitlesUi.js, line 83

Methods

private #onDataReady(data, topic)

Resets UI state and builds menu when new media data arrives.

Parameters:
Name Type Description
data Object

Event data.

Parameters:
Name Type Description
text Array<Data~mediaItem_text>

Updated text tracks.

topic string

Event topic.

Listens
data/ready
data/update
Source
SubtitlesUi.js, line 154

private #onNoMedia()

Resets UI state when no media is available.

Listens
data/nomedia
Source
SubtitlesUi.js, line 179

private #onActive(data)

Handles active track notifications from the engine.

Parameters:
Name Type Description
data Object

Active payload.

Parameters:
Name Type Description
index number

Active track index.

Listens
subtitles/active
Source
SubtitlesUi.js, line 191

private #onMenuSelected(sel)

Handles subtitle menu selections.

Parameters:
Name Type Description
sel number

Selected menu index (includes "off" at position 0).

Fires
subtitles/selected
Source
SubtitlesUi.js, line 203

private #onFontSelected(index, item)

Handles font size menu selections.

Parameters:
Name Type Description
index number

Selected index.

item Object

Selected menu item.

Parameters:
Name Type Description
value string

The font size value.

Fires
subtitles/fontsize
Source
SubtitlesUi.js, line 223

private #createMenu()

Builds the menu entries based on current tracks.

Source
SubtitlesUi.js, line 233

private #setFontMenu(fontSize)

Syncs font menu UI selection.

Parameters:
Name Type Description
fontSize string

The font size to select.

Source
SubtitlesUi.js, line 252

private #resetMenus()

Resets menus to an empty state and restores font selection.

Source
SubtitlesUi.js, line 263

destroy()

Cleans up menus and subscriptions.

Source
SubtitlesUi.js, line 278