TextTrackSettings

Manipulate Text Tracks settings.

Constructor

new TextTrackSettings(player, optionsopt)

Creates an instance of this class.

Parameters:
Name Type Attributes Description
player Player

The Player that this class should be attached to.

options Object <optional>

The key/value store of player options.

Extends

Methods

$(selector, contextopt) → {Element|null}

Find a single DOM element matching a selector. This can be within the Components contentEl() or another custom context.

Parameters:
Name Type Attributes Default Description
selector string

A valid CSS selector, which will be passed to querySelector.

context Element | string <optional>
this.contentEl()

A DOM element within which to query. Can also be a selector string in which case the first matching element will get used as context. If missing this.contentEl() gets used. If this.contentEl() returns nothing it falls back to document.

Returns:
Element | null -

the dom element that was found, or null

Inherited From:
See:

$$(selector, contextopt) → {NodeList}

Finds all DOM element matching a selector. This can be within the Components contentEl() or another custom context.

Parameters:
Name Type Attributes Default Description
selector string

A valid CSS selector, which will be passed to querySelectorAll.

context Element | string <optional>
this.contentEl()

A DOM element within which to query. Can also be a selector string in which case the first matching element will get used as context. If missing this.contentEl() gets used. If this.contentEl() returns nothing it falls back to document.

Returns:
NodeList -

a list of dom elements that were found

Inherited From:
See:

addChild(child, optionsopt, indexopt) → {Component}

Add a child Component inside the current Component.

Parameters:
Name Type Attributes Default Description
child string | Component

The name or instance of a child to add.

options Object <optional>
{}

The key/value store of options that will get passed to children of the child.

index number <optional>
this.children_.length

The index to attempt to add a child into.

Returns:
Component -

The Component that gets added as a child. When using a string the Component will get created by this process.

Inherited From:

addClass(classToAdd) → {Component}

Add a CSS class name to the Components element.

Parameters:
Name Type Description
classToAdd string

CSS class name to add

Returns:
Component -

Returns itself; method can be chained.

Inherited From:

abstract buildCSSClass() → {string}

Builds the default DOM class name. Should be overriden by sub-components.

Returns:
string -

The DOM class name for this object.

Inherited From:

children() → {Array}

Get an array of all child components

Returns:
Array -

The children

Inherited From:

clearInterval(intervalId) → {number}

Clears an interval that gets created via window.setInterval or Component#setInterval. If you set an inteval via Component#setInterval use this function instead of window.clearInterval. If you don't your dispose listener will not get cleaned up until Component#dispose!

Parameters:
Name Type Description
intervalId number

The id of the interval to clear. The return value of Component#setInterval or window.setInterval.

Returns:
number -

Returns the interval id that was cleared.

Inherited From:
See:

clearTimeout(timeoutId) → {number}

Clears a timeout that gets created via window.setTimeout or Component#setTimeout. If you set a timeout via Component#setTimeout use this function instead of window.clearTimout. If you don't your dispose listener will not get cleaned up until Component#dispose!

Parameters:
Name Type Description
timeoutId number

The id of the timeout to clear. The return value of Component#setTimeout or window.setTimeout.

Returns:
number -

Returns the timeout id that was cleared.

Inherited From:
See:

contentEl() → {Element}

Return the Components DOM element. This is where children get inserted. This will usually be the the same as the element returned in Component#el.

Returns:
Element -

The content element for this Component.

Inherited From:

createEl() → {Element}

Create the component's DOM element

Returns:
Element -

The element that was created.

Overrides:

currentDimension(widthOrHeight) → {number}

Get the width or the height of the Component elements computed style. Uses window.getComputedStyle.

Parameters:
Name Type Description
widthOrHeight string

A string containing 'width' or 'height'. Whichever one you want to get.

Returns:
number -

The dimension that gets asked for or 0 if nothing was set for that dimension.

Inherited From:

currentDimensions() → {Component~DimensionObject}

Get an object that contains width and height values of the Components computed style.

Returns:
Component~DimensionObject -

The dimensions of the components element

Inherited From:

currentHeight() → {number}

Get the height of the Components computed style. Uses window.getComputedStyle.

Returns:
number -

height The height of the Components computed style.

Inherited From:

currentWidth() → {number}

Get the width of the Components computed style. Uses window.getComputedStyle.

Returns:
number -

width The width of the Components computed style.

Inherited From:

dimension(widthOrHeight, numopt, skipListenersopt) → {Component}

Get or set width or height of the Component element. This is the shared code for the Component#width and Component#height.

Things to know:

  • If the width or height in an number this will return the number postfixed with 'px'.
  • If the width/height is a percent this will return the percent postfixed with '%'
  • Hidden elements have a width of 0 with window.getComputedStyle. This function defaults to the Components style.width and falls back to window.getComputedStyle. See this for more information
  • If you want the computed style of the component, use Component#currentWidth and {Component#currentHeight
Parameters:
Name Type Attributes Description
widthOrHeight string

8 'width' or 'height'

num number | string <optional>

8 New dimension

skipListeners boolean <optional>

Skip resize event trigger

Fires:
Returns:
Component -
  • the dimension when getting or 0 if unset
      - Returns itself when setting; method can be chained.
Inherited From:

dimensions(width, height) → {Component}

Set both the width and height of the Component element at the same time.

Parameters:
Name Type Description
width number | string

Width to set the Components element to.

height number | string

Height to set the Components element to.

Returns:
Component -

Returns itself; method can be chained.

Inherited From:

dispose()

Dispose of the Component and all child components.

Fires:
Inherited From:

el() → {Element}

Get the Components DOM element

Returns:
Element -

The DOM element for this Component.

Inherited From:

enableTouchActivity()

This function reports user activity whenever touch events happen. This can get turned off by any sub-components that wants touch events to act another way.

Report user touch activity when touch events occur. User activity gets used to determine when controls should show/hide. It is simple when it comes to mouse events, because any mouse event should show the controls. So we capture mouse events that bubble up to the player and report activity when that happens. With touch events it isn't as easy as touchstart and touchend toggle player controls. So touch events can't help us at the player level either.

User activity gets checked asynchronously. So what could happen is a tap event on the video turns the controls off. Then the touchend event bubbles up to the player. Which, if it reported user activity, would turn the controls right back on. We also don't want to completely block touch events from bubbling up. Furthermore a touchmove event and anything other than a tap, should not turn controls back on.

Listens to Events:
  • Component#event:touchstart
  • Component#event:touchmove
  • Component#event:touchend
  • Component#event:touchcancel
Inherited From:

getAttribute(attribute) → {string|null}

Get the value of an attribute on the Components element.

Parameters:
Name Type Description
attribute string

Name of the attribute to get the value from.

Returns:
string | null -
  • The value of the attribute that was asked for.
      - Can be an empty string on some browsers if the attribute does not exist
        or has no value
      - Most browsers will return null if the attibute does not exist or has
        no value.
Inherited From:
See:

getChild(name) → {Component|undefined}

Returns the child Component with the given name.

Parameters:
Name Type Description
name string

The name of the child Component to get.

Returns:
Component | undefined -

The child Component with the given name or undefined.

Inherited From:

getChildById(id) → {Component|undefined}

Returns the child Component with the given id.

Parameters:
Name Type Description
id string

The id of the child Component to get.

Returns:
Component | undefined -

The child Component with the given id or undefined.

Inherited From:

getValues() → {Object}

Gets an object of text track settings (or null).

Returns:
Object -

An object with config values parsed from the DOM or localStorage.

hasClass(classToCheck) → {boolean}

Check if a component's element has a CSS class name.

Parameters:
Name Type Description
classToCheck string

CSS class name to check.

Returns:
boolean -
  • True if the Component has the class.
      - False if the `Component` does not have the class`
Inherited From:

height(numopt, skipListenersopt) → {Component|number|string}

Get or set the height of the component based upon the CSS styles. See Component#dimension for more detailed information.

Parameters:
Name Type Attributes Description
num number | string <optional>

The height that you want to set postfixed with '%', 'px' or nothing.

skipListeners boolean <optional>

Skip the resize event trigger

Returns:
Component | number | string -
  • The width when getting, zero if there is no width. Can be a string
        postpixed with '%' or 'px'.
      - Returns itself when setting; method can be chained.
Inherited From:

hide() → {Component}

Hide the Components element if it is currently showing by adding the 'vjs-hidden` class name to it.

Returns:
Component -

Returns itself; method can be chained.

Inherited From:

id() → {string}

Get this Components ID

Returns:
string -

The id of this Component

Inherited From:

initChildren()

Add and initialize default child Components based upon options.

Inherited From:

localize(string) → {string}

Localize a string given the string in english.

Parameters:
Name Type Description
string string

The string to localize.

Returns:
string -

The localized string or if no localization exists the english string.

Inherited From:

name() → {string}

Get the Components name. The name gets used to reference the Component and is set during registration.

Returns:
string -

The name of this Component.

Inherited From:

off(firstopt, secondopt, thirdopt) → {Component}

Remove an event listener from this Components element. If the second argument is exluded all listeners for the type passed in as the first argument will be removed.

Parameters:
Name Type Attributes Description
first string | Component | Array.<string> <optional>

The event name, and array of event names, or another Component.

second EventTarget~EventListener | string | Array.<string> <optional>

The listener function, an event name, or an Array of events names.

third EventTarget~EventListener <optional>

The event handler if first is a Component and second is an event name or an Array of event names.

Returns:
Component -

Returns itself; method can be chained.

Inherited From:

on(firstopt, secondopt, thirdopt) → {Component}

Add an event listener to this Components element.

The benefit of using this over the following:

  • VjsEvents.on(otherElement, 'eventName', myFunc)
  • otherComponent.on('eventName', myFunc)

  • Is that the listeners will get cleaned up when either component gets disposed.

  • It will also bind myComponent as the context of myFunc.

    NOTE: If you remove the element from the DOM that has used on you need to

     clean up references using: `myComponent.trigger(el, 'dispose')`
     This will also allow the browser to garbage collect it. In special
     cases such as with `window` and `document`, which are both permanent,
     this is not necessary.
Parameters:
Name Type Attributes Description
first string | Component | Array.<string> <optional>

The event name, and array of event names, or another Component.

second EventTarget~EventListener | string | Array.<string> <optional>

The listener function, an event name, or an Array of events names.

third EventTarget~EventListener <optional>

The event handler if first is a Component and second is an event name or an Array of event names.

Listens to Events:
Returns:
Component -

Returns itself; method can be chained.

Inherited From:

one(firstopt, secondopt, thirdopt) → {Component}

Add an event listener that gets triggered only once and then gets removed.

Parameters:
Name Type Attributes Description
first string | Component | Array.<string> <optional>

The event name, and array of event names, or another Component.

second EventTarget~EventListener | string | Array.<string> <optional>

The listener function, an event name, or an Array of events names.

third EventTarget~EventListener <optional>

The event handler if first is a Component and second is an event name or an Array of event names.

Returns:
Component -

Returns itself; method can be chained.

Inherited From:

options(obj) → {Object}

Deep merge of options objects with new options.

Note: When both obj and options contain properties whose values are objects. The two properties get merged using module:mergeOptions

Parameters:
Name Type Description
obj Object

The object that contains new options.

Returns:
Object -

A new object of this.options_ and obj merged together.

Inherited From:
Deprecated:
  • since version 5

player() → {Player}

Return the Player that the Component has attached to.

Returns:
Player -

The player that this Component has attached to.

Inherited From:

ready(fn, syncopt) → {Component}

Bind a listener to the component's ready state. If the ready event has already happened it will trigger the function immediately.

Parameters:
Name Type Attributes Default Description
fn Component~ReadyCallback

A function to call when ready is triggered.

sync boolean <optional>
false

Execute the listener synchronously if Component is ready.

Returns:
Component -

Returns itself; method can be chained.

Inherited From:

removeAttribute(attribute) → {Component}

Remove an attribute from the Components element.

Parameters:
Name Type Description
attribute string

Name of the attribute to remove.

Returns:
Component -

Returns itself; method can be chained.

Inherited From:
See:

removeChild(component)

Remove a child Component from this Components list of children. Also removes the child Components element from this Components element.

Parameters:
Name Type Description
component Component

The child Component to remove.

Inherited From:

removeClass(classToRemove) → {Component}

Remove a CSS class name from the Components element.

Parameters:
Name Type Description
classToRemove string

CSS class name to remove

Returns:
Component -

Returns itself; method can be chained.

Inherited From:

restoreSettings()

Restore texttrack settings from localStorage

saveSettings()

Save text track settings to localStorage

setAttribute(attribute, value) → {Component}

Set the value of an attribute on the Component's element

Parameters:
Name Type Description
attribute string

Name of the attribute to set.

value string

Value to set the attribute to.

Returns:
Component -

Returns itself; method can be chained.

Inherited From:
See:

setDefaults()

Sets all