new SpatialNavigation(player)
Constructs a SpatialNavigation instance with initial settings. Sets up the player instance, and prepares the spatial navigation system.
| Name | Type | Description |
|---|---|---|
player |
Player |
The Video.js player instance to which the spatial navigation is attached. |
Extends
Members
-
An object containing event names as keys and booleans as values.
NOTE: If an event name is set to a true value here
EventTarget#triggerwill have extra functionality. See that function for more information.Properties:
Name Type Description EventTarget.prototype.allowedEvents_
Methods
-
add(component)
-
Adds a component to the array of focusable components.
Name Type Description componentComponent The
Componentto be added. -
An alias of
EventTarget#on. AllowsEventTargetto mimic the standard DOM API.- See:
-
This function will add an
event listenerthat gets triggered only once and is removed from all events. This is like adding an array ofevent listeners withEventTarget#onthat callsEventTarget#offon all events the first time it is triggered.Name Type Description typestring | Array.<string> An event name or an array of event names.
fnfunction The function to be called once for each event name.
-
calculateDistance_(center1, center2, direction){number}
-
Calculates the distance between two points, adjusting the calculation based on the specified navigation direction.
Name Type Description center1Object The center point of the first element.
center2Object The center point of the second element.
directionstring The direction of navigation ('up', 'down', 'left', 'right').
Returns:
Type Description number The calculated distance between the two centers. -
clear()
-
Clears array of focusable components.
-
An alias of
EventTarget#trigger. AllowsEventTargetto mimic the standard DOM API.- See:
-
findBestCandidate_(currentCenter, candidates, direction){Object|null}
-
Finds the best candidate on the current center position, the list of candidates, and the specified navigation direction.
Name Type Description currentCenterObject The center position of the current focused component element.
candidatesArray An array of candidate components to receive focus.
directionstring The direction of navigation ('up', 'down', 'left', 'right').
Returns:
Type Description Object | null The component that is the best candidate for receiving focus. -
findSuitableDOMChild(component){HTMLElement|null}
-
Finds a suitable child element within the provided component's DOM element.
Name Type Description componentObject The component containing the DOM element to search within.
Returns:
Type Description HTMLElement | null Returns the suitable child element if found, or null if not found. -
focus(component)
-
Focuses on a given component. If the component is available to be focused, it focuses on the component. If not, it attempts to find a suitable DOM child within the component and focuses on it.
Name Type Description componentComponent The component to be focused.
-
getCurrentComponent(target){Component|null}
-
Gets the currently focused component from the list of focusable components. If a target element is provided, it uses that element to find the corresponding component. If no target is provided, it defaults to using the document's currently active element.
Name Type Description targetHTMLElement optional The DOM element to check against the focusable components. If not provided,
document.activeElementis used.Returns:
Type Description Component | null - Returns the focused component if found among the focusable components, otherwise returns null if no matching component is found.
-
handlePlayerBlur_(event)
-
Handles Player Blur.
Name Type Description eventstring | Event | Object The name of the event, an
Event, or an object with a key of type set to an event name.Calls for handling of the Player Blur if: *The next focused element is not a child of current focused element & The next focused element is not a child of the Player. *There is no next focused element
-
handlePlayerFocus_()
-
Handles the Player focus event.
Calls for handling of the Player Focus if current element is focusable.
-
isInDirection_(srcRect, targetRect, direction){boolean}
-
Determines if a target rectangle is in the specified navigation direction relative to a source rectangle.
Name Type Description srcRectObject The bounding rectangle of the source element.
targetRectObject The bounding rectangle of the target element.
directionstring The navigation direction ('up', 'down', 'left', 'right').
Returns:
Type Description boolean True if the target is in the specified direction relative to the source. -
move(direction)
-
Navigates to the next focusable component based on the specified direction.
Name Type Description directionstring 'up', 'down', 'left', 'right'
-
Removes an
event listenerfor a specific event from an instance ofEventTarget. This makes it so that theevent listenerwill no longer get called when the named event happens.Name Type Description typestring | Array.<string> An event name or an array of event names.
fnfunction The function to remove.
-
Adds an
event listenerto an instance of anEventTarget. Anevent listeneris a function that will get called when an event with a certain name gets triggered.Name Type Description typestring | Array.<string> An event name or an array of event names.
fnfunction The function to call with
EventTargets -
This function will add an
event listenerthat gets triggered only once. After the first trigger it will get removed. This is like adding anevent listenerwithEventTarget#onthat callsEventTarget#offon itself.Name Type Description typestring | Array.<string> An event name or an array of event names.
fnfunction The function to be called once for each event name.
-
onKeyDown_(event)
-
Responds to keydown events for spatial navigation and media control.
Determines if spatial navigation or media control is active and handles key inputs accordingly.
Name Type Description eventKeyboardEvent The keydown event to be handled.
-
pause()
-
Pauses the spatial navigation functionality. This method sets a flag that can be used to temporarily disable the navigation logic.
-
performMediaAction_(key)
-
Performs media control actions based on the given key input.
Controls the playback and seeking functionalities of the media player.
Name Type Description keystring The key representing the media action to be performed. Accepted keys: 'play', 'pause', 'ff' (fast-forward), 'rw' (rewind).
-
refocusComponent()
-
Focus the last focused component saved before blur on player.
-
remove(component)
-
Removes component from the array of focusable components.
Name Type Description componentComponent The component to be removed from the focusable components array.
-
An alias of
EventTarget#off. AllowsEventTargetto mimic the standard DOM API.- See:
-
resume()
-
Resumes the spatial navigation functionality if it has been paused. This method resets the pause flag, re-enabling the navigation logic.
-
start()
-
Starts the spatial navigation by adding a keydown event listener to the video container. This method ensures that the event listener is added only once.
-
stop()
-
Stops the spatial navigation by removing the keydown event listener from the video container. Also sets the
isListening_flag to false. -
This function causes an event to happen. This will then cause any
event listenersthat are waiting for that event, to get called. If there are noevent listenersfor an event then nothing will happen.If the name of the
Eventthat is being triggered is inEventTarget.allowedEvents_. Trigger will also call theon+uppercaseEventNamefunction.Example: 'click' is in
EventTarget.allowedEvents_, so, trigger will attempt to callonClickif it exists.Name Type Description eventstring | EventTarget~Event | Object The name of the event, an
Event, or an object with a key of type set to an event name. -
updateFocusableComponents(){Array}
-
Gets a set of focusable components.
Returns:
Type Description Array Returns an array of focusable components. -
userSeek_(ct)
-
Prevent liveThreshold from causing seeks to seem like they are not happening from a user perspective.
Name Type Description ctnumber current time to seek to