Skip to content

Commit a715142

Browse files
Control the font used for book buttons in RAB books (BL-16351)
1 parent a5e0af9 commit a715142

5 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/BloomBrowserUI/bookEdit/js/collectionSettings.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ declare function GetSettings(): ICollectionSettings;
55

66
interface ICollectionSettings {
77
languageForNewTextBoxes: string;
8+
language1Font: string;
89
defaultSourceLanguage: string;
910
defaultSourceLanguage2: string;
1011
currentCollectionLanguage2: string;

src/BloomBrowserUI/bookEdit/js/linkGrid.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1+
/// <reference path="./collectionSettings.d.ts" />
2+
13
import WebSocketManager, {
24
IBloomWebSocketEvent,
35
} from "../../utils/WebSocketManager";
46
import { postJson } from "../../utils/bloomApi";
57
import { showBookGridSetupDialog } from "../../react_components/BookGridSetup/BookGridSetupDialog";
68
import { Link } from "../../react_components/BookGridSetup/BookLinkTypes";
79

10+
function getLanguage1Font(): string {
11+
const settings = GetSettings() as ICollectionSettings;
12+
return settings.language1Font;
13+
}
14+
15+
function applyLanguage1Font(element: HTMLElement) {
16+
const language1Font = getLanguage1Font();
17+
if (!language1Font) {
18+
return;
19+
}
20+
21+
Array.from(element.getElementsByTagName("p")).forEach((p) => {
22+
p.style.fontFamily = language1Font;
23+
});
24+
}
25+
826
export function setupBookLinkGrids(container: HTMLElement) {
927
// Add skeleton to empty grids on initial setup
1028
const linkGrids = Array.from(
1129
container.getElementsByClassName("bloom-link-grid"),
1230
) as HTMLElement[];
1331
for (const linkGrid of linkGrids) {
32+
applyLanguage1Font(linkGrid);
1433
addSkeletonIfEmpty(linkGrid as HTMLElement);
1534
// In case anyone wonders why this works here but will not on most canvas elements
1635
// and their children...we put a rule in basepage.less that puts bloom-link-grid
@@ -96,10 +115,13 @@ export function editLinkGrid(linkGrid: HTMLElement) {
96115
const p = document.createElement("p");
97116
p.textContent =
98117
link.book.title || link.book.folderName || "";
118+
p.style.fontFamily = getLanguage1Font();
99119
button.appendChild(p);
100120

101121
linkGrid.appendChild(button);
102122
});
123+
124+
applyLanguage1Font(linkGrid);
103125
}
104126
},
105127
);

src/BloomBrowserUI/bookEdit/test/GetSettingsMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function GetSettings() {
1717
v.currentCollectionLanguage2 = "tpi";
1818
v.currentCollectionLanguage3 = "fr";
1919
v.languageForNewTextBoxes = "en";
20+
v.language1Font = "Andika";
2021
v.browserRoot = "";
2122
v.topics = [
2223
"Agriculture",

src/BloomBrowserUI/vitest.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ globalThis.jQuery = jQuery;
475475
currentCollectionLanguage2: "tpi",
476476
currentCollectionLanguage3: "fr",
477477
languageForNewTextBoxes: "en",
478+
language1Font: "Andika",
478479
browserRoot: "",
479480
topics: [
480481
"Agriculture",

src/BloomExe/Book/RuntimeInformationInjector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ IFileLocator fileLocator
472472
}
473473

474474
d.Add("languageForNewTextBoxes", bookData.Language1.Tag);
475+
d.Add("language1Font", bookData.Language1.FontName ?? "");
475476

476477
// BL-2357 To aid in smart ordering of source languages in source bubble
477478
if (!String.IsNullOrEmpty(bookData.Language2Tag))

0 commit comments

Comments
 (0)