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
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class AblePlayer {
8383
this.okToPlay = false;
8484
}
8585

86-
let data = media[0].dataset;
86+
let data = $(media)[0].dataset;
8787

8888
// loop (Boolean; if present always resolves to true, regardless of value)
8989
this.loop = (data.loop !== undefined) ? true : false;
@@ -269,8 +269,8 @@ class AblePlayer {
269269
let seekbarScope = options.seekbarScope ?? data.seekbarScope;
270270
this.seekbarScope = (seekbarScope === 'chapter' || seekbarScope === 'chapters') ? 'chapter' : 'video';
271271

272-
// YouTube
273-
let youTubeId = options.youTubeId ?? data.youTubeId;
272+
// YouTube converts to youtube in data attributes.
273+
let youTubeId = options.youTubeId ?? data.youtubeId;
274274
if (youTubeId !== undefined && youTubeId !== "") {
275275
this.youTubeId = this.getYouTubeId(youTubeId);
276276
if (!this.hasPoster) {
@@ -279,17 +279,17 @@ class AblePlayer {
279279
}
280280
}
281281

282-
let youTubeDescId = options.youTubeDescId ?? data.youTubeDescId;
282+
let youTubeDescId = options.youTubeDescId ?? data.youtubeDescId;
283283
if (youTubeDescId !== undefined && youTubeDescId !== "") {
284284
this.youTubeDescId = this.getYouTubeId(youTubeDescId);
285285
}
286286

287-
let youTubeSignId = options.youTubeSignId ?? data.youTubeSignId;
287+
let youTubeSignId = options.youTubeSignId ?? data.youtubeSignSrc;
288288
if (youTubeSignId !== undefined && youTubeSignId !== "") {
289289
this.youTubeSignId = this.getYouTubeId(youTubeSignId);
290290
}
291291

292-
let youTubeNoCookie = options.youTubeNoCookie ?? data.youTubeNoCookie;
292+
let youTubeNoCookie = options.youTubeNoCookie ?? data.youtubeNoCookie;
293293
this.youTubeNoCookie = (youTubeNoCookie !== undefined && youTubeNoCookie) ? true : false;
294294

295295
// Vimeo

‎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
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ function addVimeoFunctions(AblePlayer) {
266266
// this is likely already a vimeo ID
267267
return url;
268268
} else {
269-
urlObject = new URL(url);
269+
// Try to parse as a URL. If that fails, return the string as-is. It's probably an ID.
270+
try {
271+
urlObject = new URL(url);
272+
} catch (e) {
273+
return url;
274+
}
270275
}
271276
if ( 'vimeo.com' === urlObject.hostname || 'player.vimeo.com' === urlObject.hostname ) {
272277
// this is a full Vimeo URL

0 commit comments

Comments
 (0)