Skip to content

Commit

Permalink
Merge pull request #326 from StephenMcConnel/BL-13906-FixCircularDepe…
Browse files Browse the repository at this point in the history
…ndency

fix: Remove circular dependency which caused test failures (BL-13906) (#326)
  • Loading branch information
andrew-polk authored Sep 24, 2024
2 parents 9c6fd10 + f5e71e4 commit d434614
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 42 deletions.
4 changes: 0 additions & 4 deletions src/l10n/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,5 @@
"Button.IgnoreImageDescriptions": {
"message": "Ignore Image Descriptions",
"description": "tooltip for the button to disable reading image descriptions"
},
"Video.BadVideoMessage": {
"message": "Sorry, this video cannot be played in this browser.",
"description": "message displayed when a video is invalid or missing"
}
}
33 changes: 32 additions & 1 deletion src/narration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// and video

import LiteEvent from "./event";
import { hideVideoError, showVideoError } from "./video";
// Note: trying to avoid other imports, as part of the process of moving this code to a module
// that can be shared with BloomDesktop.

Expand Down Expand Up @@ -1287,3 +1286,35 @@ export function playAllVideo(elements: HTMLVideoElement[], then: () => void) {
});
}
}

// These methods live here instead of video.ts because video.ts is already importing
// from narration.ts, and we don't want to create a circular dependency.

// We're living with this message not being localized.
const badVideoMessage = "Sorry, this video cannot be played in this browser.";

export function showVideoError(video: HTMLVideoElement): void {
const parent = video.parentElement;
if (parent) {
const divs = parent.getElementsByClassName("video-error-message");
if (divs.length === 0) {
const msgDiv = parent.ownerDocument.createElement("div");
msgDiv.className = "video-error-message normal-style";
msgDiv.textContent = badVideoMessage;
msgDiv.style.display = "block";
msgDiv.style.color = "white";
msgDiv.style.position = "absolute";
msgDiv.style.left = "10%";
msgDiv.style.top = "10%";
msgDiv.style.width = "80%";
parent.appendChild(msgDiv);
}
}
}
export function hideVideoError(video: HTMLVideoElement): void {
const parent = video.parentElement;
if (parent) {
const divs = parent.getElementsByClassName("video-error-message");
while (divs.length > 1) parent.removeChild(divs[0]);
}
}
40 changes: 3 additions & 37 deletions src/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { isMacOrIOS } from "./utilities/osUtils";
import {
currentPlaybackMode,
setCurrentPlaybackMode,
PlaybackMode
PlaybackMode,
hideVideoError,
showVideoError
} from "./narration";
import { LocalizationManager } from "./l10n/localizationManager";

// class Video contains functionality to get videos to play properly in bloom-player

Expand All @@ -15,15 +16,6 @@ export interface IPageVideoComplete {
videos: HTMLVideoElement[];
}

const uiLang = LocalizationManager.getBloomUiLanguage();
const preferredUiLanguages = uiLang === "en" ? [uiLang] : [uiLang, "en"];

const badVideoMessage = LocalizationManager.getTranslation(
"Video.BadVideoMessage",
preferredUiLanguages,
"Sorry, this video cannot be played in this browser."
);

export class Video {
private currentPage: HTMLDivElement;
private currentVideoElement: HTMLVideoElement | undefined;
Expand Down Expand Up @@ -224,29 +216,3 @@ export class Video {
}
}
}

export function showVideoError(video: HTMLVideoElement): void {
const parent = video.parentElement;
if (parent) {
const divs = parent.getElementsByClassName("video-error-message");
if (divs.length === 0) {
const msgDiv = parent.ownerDocument.createElement("div");
msgDiv.className = "video-error-message normal-style";
msgDiv.textContent = badVideoMessage;
msgDiv.style.display = "block";
msgDiv.style.color = "white";
msgDiv.style.position = "absolute";
msgDiv.style.left = "10%";
msgDiv.style.top = "10%";
msgDiv.style.width = "80%";
parent.appendChild(msgDiv);
}
}
}
export function hideVideoError(video: HTMLVideoElement): void {
const parent = video.parentElement;
if (parent) {
const divs = parent.getElementsByClassName("video-error-message");
while (divs.length > 1) parent.removeChild(divs[0]);
}
}

0 comments on commit d434614

Please sign in to comment.