Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #76 from ehapmgs/feature/hyphens
Browse files Browse the repository at this point in the history
adding hyphenations option & fix NaN value when the window is hidden
  • Loading branch information
mickael-menu authored Apr 16, 2020
2 parents e96ecbf + f6c1993 commit 6654a5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions r2-navigator-swift/EPUB/Resources/Scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ var readium = (function() {
last_known_scrollY_position = window.scrollY / document.scrollingElement.scrollHeight;
// Using Math.abs because for RTL books, the value will be negative.
last_known_scrollX_position = Math.abs(window.scrollX / document.scrollingElement.scrollWidth);

// Window is hidden
if (document.scrollingElement.scrollWidth === 0 || document.scrollingElement.scrollHeight === 0) {
return;
}

if (!ticking) {
window.requestAnimationFrame(function() {
update(isScrollModeEnabled() ? last_known_scrollY_position : last_known_scrollX_position);
Expand Down
15 changes: 15 additions & 0 deletions r2-navigator-swift/EPUB/UserSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class UserSettings {
private var fontFamily = 0
private var appearance = 0
private var verticalScroll = false
private var hyphens = false

private var publisherDefaults = true
private var textAlignment = 0
Expand All @@ -44,6 +45,13 @@ public class UserSettings {

/// Load settings from UserDefaults

// hyphens
if isKeyPresentInUserDefaults(key: ReadiumCSSName.hyphens) {
hyphens = userDefaults.bool(forKey: ReadiumCSSName.hyphens.rawValue)
} else {
hyphens = false
}

// Font size
if isKeyPresentInUserDefaults(key: ReadiumCSSName.fontSize) {
fontSize = userDefaults.float(forKey: ReadiumCSSName.fontSize.rawValue)
Expand Down Expand Up @@ -113,6 +121,13 @@ public class UserSettings {
// Build and add CSS properties
private func buildCssProperties() {

// Hyphens
userProperties.addSwitchable(onValue: "auto",
offValue: "none",
on: hyphens,
reference: ReadiumCSSReference.hyphens.rawValue,
name: ReadiumCSSName.hyphens.rawValue)

// Font size
userProperties.addIncrementable(nValue: fontSize,
min: 100,
Expand Down

0 comments on commit 6654a5d

Please sign in to comment.