Apply fixes for issues with YouTube · ableplayer/ableplayer@9b44ab4 · GitHub
Skip to content

Commit 9b44ab4

Browse files
committed
Apply fixes for issues with YouTube
See issues documented in #775
1 parent e33d502 commit 9b44ab4

5 files changed

Lines changed: 32 additions & 18 deletions

File tree

‎scripts/ableplayer-base.js‎

Lines changed: 6 additions & 6 deletions

‎scripts/control.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ function addControlFunctions(AblePlayer) {
17101710
}
17111711
}
17121712
// Change the transcript language if the transcript is not currently visible.
1713-
if ( ( ! this.$transcriptArea.is(':visible') && source === 'captions' ) || source === 'init' || source === 'transcript' ) {
1713+
if ( ( source === 'captions' && typeof this.$transcriptArea !== 'undefined' && ! this.$transcriptArea.is(':visible') ) || source === 'init' || source === 'transcript' ) {
17141714
console.log('syncTrackLanguages: transcript is not visible, so changing transcript language to ' + language);
17151715
this.transcriptCaptions = captions;
17161716
this.transcriptChapters = chapters;

‎scripts/description.js‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function addDescriptionFunctions(AblePlayer) {
2323
// readDescriptionsAloud == true if text description is to be announced audibly; otherwise false
2424
// descReader == either 'browser' or 'screenreader'
2525

26-
var deferred, promise;
26+
var deferred, promise, firstSource;
2727

2828
deferred = new this.defer();
2929
promise = deferred.promise();
@@ -35,8 +35,9 @@ function addDescriptionFunctions(AblePlayer) {
3535
// check to see if there's an open-described version of this video
3636
// checks only the first source since if a described version is provided,
3737
// it must be provided for all sources
38-
this.descFile = this.sources[0].getAttribute('data-desc-src');
39-
if (typeof this.descFile !== 'undefined') {
38+
firstSource = this.sources[0] ?? null;
39+
this.descFile = firstSource ? this.sources[0].getAttribute('data-desc-src') : null;
40+
if ( this.descFile !== null && this.descFile !== '' ) {
4041
this.hasOpenDesc = true;
4142
} else {
4243
// there's no open-described version via data-desc-src,
@@ -121,7 +122,10 @@ function addDescriptionFunctions(AblePlayer) {
121122
} else if (this.player === 'vimeo') {
122123
return (this.activeVimeoId === this.vimeoDescId);
123124
} else {
124-
return (this.sources[0].getAttribute('data-desc-src') === this.sources[0].getAttribute('src'));
125+
const firstSource = this.sources[0] ?? null;
126+
const descSrc = firstSource ? firstSource.getAttribute('data-desc-src') : null;
127+
const activeSrc = firstSource ? firstSource.getAttribute('src') : null;
128+
return ( descSrc !== null && descSrc === activeSrc );
125129
}
126130
};
127131

‎scripts/sign.js‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ import DOMPurify from 'dompurify';
44

55
function addSignFunctions(AblePlayer) {
66
AblePlayer.prototype.initSignLanguage = function() {
7+
let firstSource, localSignSrc, remoteSignSrc, hasLocalSrc, hasRemoteSrc, hasRemoteSource, ytSignSrc, signSrc, signVideo;
8+
79
this.hasSignLanguage = false;
810
// Sign language is only currently supported in HTML5 player and YouTube.
9-
var hasLocalSrc = ( this.sources[0].getAttribute('data-sign-src') !== undefined && this.sources[0].getAttribute('data-sign-src') !== "" );
11+
firstSource = this.sources[0] ?? null;
12+
localSignSrc = firstSource ? firstSource.getAttribute('data-sign-src') : null;
13+
remoteSignSrc = firstSource ? firstSource.getAttribute('data-youtube-sign-src') : null;
14+
hasLocalSrc = ( localSignSrc !== null && localSignSrc !== "" );
1015
// YouTube src can either be on a `source` element or on the `video` element.
11-
var hasRemoteSrc = ( this.$media.data('youtube-sign-src') !== undefined && this.$media.data('youtube-sign-src') !== "" );
12-
var hasRemoteSource = ( this.sources[0].getAttribute('data-youtube-sign-src') !== undefined && this.sources[0].getAttribute('data-youtube-sign-src') !== '' );
16+
hasRemoteSrc = ( this.$media.data('youtube-sign-src') !== undefined && this.$media.data('youtube-sign-src') !== "" );
17+
hasRemoteSource = ( remoteSignSrc !== null && remoteSignSrc !== '' );
1318
if ( ! this.isIOS() && ( hasLocalSrc || hasRemoteSrc || hasRemoteSource ) && ( this.player === 'html5' || this.player === 'youtube' ) ) {
1419
// check to see if there's a sign language video accompanying this video
1520
// check only the first source
1621
// If sign language is provided, it must be provided for all sources
17-
let ytSignSrc = this.youTubeSignId ?? DOMPurify.sanitize( this.sources[0].getAttribute('data-youtube-sign-src') );
18-
let signSrc = DOMPurify.sanitize( this.sources[0].getAttribute('data-sign-src') );
19-
let signVideo = DOMPurify.sanitize( this.$media.data('youtube-sign-src') );
22+
ytSignSrc = this.youTubeSignId ?? DOMPurify.sanitize( remoteSignSrc );
23+
signSrc = DOMPurify.sanitize( localSignSrc );
24+
signVideo = DOMPurify.sanitize( this.$media.data('youtube-sign-src') );
2025
this.signFile = (hasLocalSrc ) ? signSrc : false;
2126
if ( hasRemoteSrc ) {
2227
this.signYoutubeId = signVideo;

‎scripts/vimeo.js‎

Lines changed: 6 additions & 1 deletion

0 commit comments

Comments
 (0)