Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion js/adapt-vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,33 @@ class Vimeo extends ComponentView {
setupPlayer() {
this.vimeoView = this.addSubview(VimeoView, this.model.get('_media'));

this.listenToOnce(this.vimeoView, 'ready', this.setReadyStatus);
this.listenToOnce(this.vimeoView, 'ready', this.onVimeoViewReady);
}

onVimeoViewReady() {
this.setIframeAccessibleName();
this.setReadyStatus();
}

/**
* Give the player iframe an author-controlled, localisable accessible name.
* The Vimeo library otherwise only sets a `title` from the video's own
* Vimeo title, which authors cannot control or localise.
*
* When a displayTitle is set it renders as a visible component heading, so
* the iframe references that heading via aria-labelledby rather than
* duplicating the string. Otherwise the non-visible title field is used
* directly as an aria-label. Mirrors adapt-youtube#48.
*/
setIframeAccessibleName() {
const iframe = this.vimeoView.player?.element;
if (!iframe) return;
if (this.model.get('displayTitle')) {
iframe.setAttribute('aria-labelledby', `${this.model.get('_id')}-heading`);
return;
}
const title = this.model.get('title');
if (title) iframe.setAttribute('aria-label', title);
}

setupEventListeners() {
Expand Down