diff --git a/src/bloom-player-controls.tsx b/src/bloom-player-controls.tsx index 7e462cc..095ba64 100644 --- a/src/bloom-player-controls.tsx +++ b/src/bloom-player-controls.tsx @@ -33,6 +33,7 @@ import DragBar from "@material-ui/core/Slider"; import { bloomRed } from "./bloomPlayerTheme"; import { setDurationOfPagesWithoutNarration } from "./narration"; import { roundToNearestK, normalizeDigits } from "./utilities/mathUtils"; +import { fixNiceScrollOffsets } from "./scrolling"; // This component is designed to wrap a BloomPlayer with some controls // for things like pausing audio and motion, hiding and showing @@ -603,7 +604,7 @@ export const BloomPlayerControls: React.FunctionComponent = ( actualPageHeight / scaleFactor }px; overflow: hidden;}`; //alert("scale page to window completed"); - BloomPlayerCore.fixNiceScrollOffsets(page, scaleFactor); + fixNiceScrollOffsets(page, scaleFactor); if (!pageScaled) { setPageScaled(true); } diff --git a/src/bloom-player-core.tsx b/src/bloom-player-core.tsx index c7cc8eb..d7edbf2 100644 --- a/src/bloom-player-core.tsx +++ b/src/bloom-player-core.tsx @@ -2,7 +2,6 @@ bloom-player-core is responsible for all the behavior of working through a book, but without any UI controls (other than page turning). */ -/// import * as React from "react"; import * as ReactDOM from "react-dom"; import axios, { AxiosPromise } from "axios"; @@ -45,7 +44,6 @@ import { CircularProgress } from "@material-ui/core"; import { BookInfo } from "./bookInfo"; import { BookInteraction } from "./bookInteraction"; import $ from "jquery"; -import "jquery.nicescroll"; import { getQueryStringParamAndUnencode } from "./utilities/urlUtils"; import { kLocalStorageDurationKey, @@ -76,6 +74,13 @@ import { } from "./narration"; import { logSound } from "./videoRecordingSupport"; import { playSoundOf } from "./dragActivityRuntime"; +import { + addScrollbarsToPage, + ComputeNiceScrollOffsets, + kSelectorForPotentialNiceScrollElements, +} from "./scrolling"; +import { assembleStyleSheets } from "./stylesheets"; +import { c } from "vite/dist/node/types.d-aGj9QkWt"; // BloomPlayer takes a URL param that directs it to Bloom book. // (See comment on sourceUrl for exactly how.) // It displays pages from the book and allows them to be turned by dragging. @@ -239,10 +244,6 @@ function handleInputMouseEvent(event: Event) { } } -const kSelectorForPotentialNiceScrollElements = - ".bloom-translationGroup:not(.bloom-imageDescription) .bloom-editable.bloom-visibility-code-on, " + - ".scrollable"; // we added .scrollable for branding cases where the boilerplate text also needs to scroll - export class BloomPlayerCore extends React.Component { private readonly activityManager: ActivityManager = new ActivityManager(); private readonly legacyQuestionHandler: LegacyQuestionHandler; @@ -785,30 +786,6 @@ export class BloomPlayerCore extends React.Component { } } - // nicescroll doesn't properly scale the padding at the top and left of the - // scrollable area of the languageGroup divs when the page is scaled. This - // method sets offset values to correct for this. It is called whenever the - // entire window resizes, which also scales the page before this is called. - // See BL-13796. - public static fixNiceScrollOffsets(page: HTMLElement, scale: number) { - page.querySelectorAll(kSelectorForPotentialNiceScrollElements).forEach( - (group) => { - // The type definition is not correct for getNiceScroll; we expect it to return an array. - const groupNiceScroll = $(group).getNiceScroll() as any; - if (groupNiceScroll && groupNiceScroll.length > 0) { - let { topAdjust, leftAdjust } = - BloomPlayerCore.ComputeNiceScrollOffsets( - scale, - group as HTMLElement, - ); - groupNiceScroll[0].opt.railoffset.top = -topAdjust; - groupNiceScroll[0].opt.railoffset.left = -leftAdjust; - groupNiceScroll[0].resize(); - } - }, - ); - } - private collectBodyAttributes(originalBodyElement: HTMLBodyElement) { // When working on the ABC-BARMM branding/XMatter pack, we discovered that the classes on the // Desktop body element were not getting passed into bloom-player. @@ -1011,9 +988,18 @@ export class BloomPlayerCore extends React.Component { // Make sure you only set state.styleRules once per book. // Otherwise, it wreaks havoc on scoped styles. See BL-9504. if (isNewBook) { - const combinedStyle = await this.assembleStyleSheets( - this.htmlElement, - ); + var combinedStyle; + try { + combinedStyle = await assembleStyleSheets( + this.htmlElement!, + this.urlPrefix, + this.bookInfo, + () => this.legacyQuestionHandler.getPromiseForAnyQuizCss(), + ); + } catch (e) { + this.HandleLoadingError(e); + combinedStyle = ""; + } // We're about to start rendering with isLoading false. That means the spinning circle is // replaced with a swiper control showing the actual book contents. We need to do certain // things differently while swiper is getting stabilized on the first page; this gets set @@ -1647,285 +1633,6 @@ export class BloomPlayerCore extends React.Component { } } - // Make a