Skip to content

Commit

Permalink
Merge pull request #675 from gotson/feat/initial-appearance
Browse files Browse the repository at this point in the history
better appearance handling in initialUserSettings
  • Loading branch information
aferditamuriqi authored Jan 31, 2024
2 parents 32bddbb + 38e8ba5 commit 293f01e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
54 changes: 29 additions & 25 deletions src/model/user-settings/UserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ export class UserSettings implements IUserSettings {
log.log(settings.verticalScroll);
}
if (initialUserSettings.appearance) {
settings.appearance = UserSettings.appearanceValues.findIndex(
(el: any) => el === initialUserSettings.appearance
);
settings.appearance = UserSettings.parseAppearanceSetting(initialUserSettings.appearance)
let prop = settings.userProperties.getByRef(ReadiumCSS.APPEARANCE_REF);
if (prop) {
prop.value = settings.appearance;
Expand Down Expand Up @@ -989,28 +987,7 @@ export class UserSettings implements IUserSettings {

async applyUserSettings(userSettings: Partial<UserSettings>): Promise<void> {
if (userSettings.appearance) {
let a: string;
if (
userSettings.appearance === "day" ||
userSettings.appearance === "readium-default-on"
) {
a = UserSettings.appearanceValues[0];
} else if (
userSettings.appearance === "sepia" ||
userSettings.appearance === "readium-sepia-on"
) {
a = UserSettings.appearanceValues[1];
} else if (
userSettings.appearance === "night" ||
userSettings.appearance === "readium-night-on"
) {
a = UserSettings.appearanceValues[2];
} else {
a = userSettings.appearance;
}
this.appearance = UserSettings.appearanceValues.findIndex(
(el: any) => el === a
);
this.appearance = UserSettings.parseAppearanceSetting(userSettings.appearance)
let prop = this.userProperties?.getByRef(ReadiumCSS.APPEARANCE_REF);
if (prop) {
prop.value = this.appearance;
Expand Down Expand Up @@ -1138,6 +1115,33 @@ export class UserSettings implements IUserSettings {
}
}

private static parseAppearanceSetting(
inputSetting: InitialUserSettings["appearance"]
): number {
let a: string;
if (
inputSetting === "day" ||
inputSetting === "readium-default-on"
) {
a = UserSettings.appearanceValues[0];
} else if (
inputSetting === "sepia" ||
inputSetting === "readium-sepia-on"
) {
a = UserSettings.appearanceValues[1];
} else if (
inputSetting === "night" ||
inputSetting === "readium-night-on"
) {
a = UserSettings.appearanceValues[2];
} else {
a = inputSetting;
}
return UserSettings.appearanceValues.findIndex(
(el: any) => el === a
);
}

async scroll(scroll: boolean): Promise<void> {
const position = this.view?.getCurrentPosition();
this.verticalScroll = scroll;
Expand Down
2 changes: 1 addition & 1 deletion viewer/index_dita.html
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@
},
]
let userSettings = {
// appearance: "readium-sepia-on", //readium-default-on, readium-night-on, readium-sepia-on
// appearance: "sepia", //readium-default-on, day, readium-night-on, night, readium-sepia-on, sepia
// fontFamily: "serif", //Original, serif, sans-serif
// textAlignment: "start", //"auto", "justify", "start"
// columnCount: "1", // "auto", "1", "2"
Expand Down

0 comments on commit 293f01e

Please sign in to comment.