@internetarchive/bookreader 5.0.0-9 → 5.0.0-91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +21 -19
- package/.github/workflows/node.js.yml +76 -11
- package/.github/workflows/npm-publish.yml +6 -20
- package/.testcaferc.js +10 -0
- package/BookReader/BookReader.css +404 -1125
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.LICENSE.txt +20 -20
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +1782 -0
- package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +7 -0
- package/BookReader/ia-bookreader-bundle.js.map +1 -0
- package/BookReader/icons/1up.svg +1 -1
- package/BookReader/icons/2up.svg +1 -1
- package/BookReader/icons/advance.svg +1 -1
- package/BookReader/icons/chevron-right.svg +1 -1
- package/BookReader/icons/close-circle-dark.svg +1 -1
- package/BookReader/icons/close-circle.svg +1 -1
- package/BookReader/icons/fullscreen.svg +1 -1
- package/BookReader/icons/fullscreen_exit.svg +1 -1
- package/BookReader/icons/hamburger.svg +1 -1
- package/BookReader/icons/left-arrow.svg +1 -1
- package/BookReader/icons/magnify-minus.svg +1 -1
- package/BookReader/icons/magnify-plus.svg +1 -1
- package/BookReader/icons/magnify.svg +1 -1
- package/BookReader/icons/pause.svg +1 -1
- package/BookReader/icons/play.svg +1 -1
- package/BookReader/icons/playback-speed.svg +1 -1
- package/BookReader/icons/read-aloud.svg +1 -1
- package/BookReader/icons/review.svg +1 -1
- package/BookReader/icons/thumbnails.svg +1 -1
- package/BookReader/icons/voice.svg +1 -0
- package/BookReader/icons/volume-full.svg +1 -1
- package/BookReader/images/BRicons.svg +3 -3
- package/BookReader/images/books_graphic.svg +1 -1
- package/BookReader/images/icon_book.svg +1 -1
- package/BookReader/images/icon_bookmark.svg +1 -1
- package/BookReader/images/icon_gear.svg +1 -1
- package/BookReader/images/icon_hamburger.svg +1 -1
- package/BookReader/images/icon_home.svg +1 -1
- package/BookReader/images/icon_info.svg +1 -1
- package/BookReader/images/icon_one_page.svg +1 -1
- package/BookReader/images/icon_pause.svg +1 -1
- package/BookReader/images/icon_play.svg +1 -1
- package/BookReader/images/icon_playback-rate.svg +1 -1
- package/BookReader/images/icon_search_button.svg +1 -1
- package/BookReader/images/icon_share.svg +1 -1
- package/BookReader/images/icon_skip-ahead.svg +1 -1
- package/BookReader/images/icon_skip-back.svg +1 -1
- package/BookReader/images/icon_speaker.svg +1 -1
- package/BookReader/images/icon_speaker_open.svg +1 -1
- package/BookReader/images/icon_thumbnails.svg +1 -1
- package/BookReader/images/icon_toc.svg +1 -1
- package/BookReader/images/icon_two_pages.svg +1 -1
- package/BookReader/images/marker_chap-off.svg +1 -1
- package/BookReader/images/marker_chap-on.svg +1 -1
- package/BookReader/images/marker_srch-on.svg +1 -1
- package/BookReader/images/unviewable_page.png +0 -0
- package/BookReader/jquery-3.js +2 -0
- package/BookReader/jquery-3.js.LICENSE.txt +24 -0
- package/BookReader/plugins/plugin.archive_analytics.js +1 -1
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
- package/BookReader/plugins/plugin.autoplay.js +1 -1
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.chapters.js +25 -1
- package/BookReader/plugins/plugin.chapters.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.chapters.js.map +1 -1
- package/BookReader/plugins/plugin.iframe.js +1 -1
- package/BookReader/plugins/plugin.iframe.js.map +1 -1
- package/BookReader/plugins/plugin.iiif.js +2 -0
- package/BookReader/plugins/plugin.iiif.js.map +1 -0
- package/BookReader/plugins/plugin.resume.js +1 -1
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +2 -1
- package/BookReader/plugins/plugin.search.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +2 -1
- package/BookReader/plugins/plugin.text_selection.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +1 -1
- package/BookReader/plugins/plugin.tts.js.LICENSE.txt +2 -0
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
- package/BookReader/webcomponents-bundle.js +3 -0
- package/BookReader/webcomponents-bundle.js.LICENSE.txt +9 -0
- package/BookReader/webcomponents-bundle.js.map +1 -0
- package/BookReaderDemo/BookReaderDemo.css +18 -19
- package/BookReaderDemo/BookReaderJSAdvanced.js +0 -3
- package/BookReaderDemo/BookReaderJSSimple.js +1 -0
- package/BookReaderDemo/IADemoBr.js +144 -0
- package/BookReaderDemo/demo-advanced.html +2 -2
- package/BookReaderDemo/demo-embed-iframe-src.html +2 -1
- package/BookReaderDemo/demo-fullscreen-mobile.html +3 -5
- package/BookReaderDemo/demo-fullscreen.html +2 -4
- package/BookReaderDemo/demo-iiif.html +99 -12
- package/BookReaderDemo/demo-internetarchive.html +214 -18
- package/BookReaderDemo/demo-multiple.html +2 -1
- package/BookReaderDemo/demo-preview-pages.html +526 -525
- package/BookReaderDemo/demo-simple.html +2 -1
- package/BookReaderDemo/demo-vendor-fullscreen.html +2 -4
- package/BookReaderDemo/ia-multiple-volumes-manifest.js +170 -0
- package/BookReaderDemo/immersion-1up.html +2 -2
- package/BookReaderDemo/immersion-mode.html +2 -4
- package/BookReaderDemo/toggle_controls.html +3 -2
- package/BookReaderDemo/view_mode.html +2 -1
- package/BookReaderDemo/viewmode-cycle.html +2 -3
- package/CHANGELOG.md +600 -33
- package/README.md +14 -1
- package/babel.config.js +20 -0
- package/codecov.yml +6 -0
- package/index.html +5 -2
- package/jsconfig.json +19 -0
- package/netlify.toml +9 -0
- package/package.json +70 -62
- package/renovate.json +52 -0
- package/scripts/preversion.js +0 -1
- package/src/BookNavigator/assets/bookmark-colors.js +1 -1
- package/src/BookNavigator/assets/button-base.js +5 -2
- package/src/BookNavigator/assets/ia-logo.js +17 -0
- package/src/BookNavigator/assets/icon_checkmark.js +1 -1
- package/src/BookNavigator/assets/icon_close.js +1 -1
- package/src/BookNavigator/book-navigator.js +590 -0
- package/src/BookNavigator/bookmarks/bookmark-button.js +3 -2
- package/src/BookNavigator/bookmarks/bookmark-edit.js +3 -4
- package/src/BookNavigator/bookmarks/bookmarks-list.js +2 -3
- package/src/BookNavigator/bookmarks/bookmarks-loginCTA.js +4 -9
- package/src/BookNavigator/bookmarks/bookmarks-provider.js +27 -17
- package/src/BookNavigator/bookmarks/ia-bookmarks.js +116 -67
- package/src/BookNavigator/delete-modal-actions.js +1 -1
- package/src/BookNavigator/downloads/downloads-provider.js +36 -21
- package/src/BookNavigator/downloads/downloads.js +29 -25
- package/src/BookNavigator/search/search-provider.js +50 -28
- package/src/BookNavigator/search/search-results.js +24 -10
- package/src/BookNavigator/sharing.js +27 -0
- package/src/BookNavigator/viewable-files.js +95 -0
- package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +13 -12
- package/src/BookNavigator/visual-adjustments/visual-adjustments.js +7 -7
- package/src/BookReader/BookModel.js +79 -43
- package/src/BookReader/DragScrollable.js +233 -0
- package/src/BookReader/ImageCache.js +48 -15
- package/src/BookReader/Mode1Up.js +56 -351
- package/src/BookReader/Mode1UpLit.js +388 -0
- package/src/BookReader/Mode2Up.js +73 -1318
- package/src/BookReader/Mode2UpLit.js +777 -0
- package/src/BookReader/ModeCoordinateSpace.js +29 -0
- package/src/BookReader/ModeSmoothZoom.js +312 -0
- package/src/BookReader/ModeThumb.js +19 -13
- package/src/BookReader/Navbar/Navbar.js +70 -54
- package/src/BookReader/PageContainer.js +116 -22
- package/src/BookReader/ReduceSet.js +3 -3
- package/src/BookReader/Toolbar/Toolbar.js +14 -41
- package/src/BookReader/events.js +2 -3
- package/src/BookReader/options.js +75 -15
- package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
- package/src/BookReader/utils/ScrollClassAdder.js +31 -0
- package/src/BookReader/utils/SelectionObserver.js +45 -0
- package/src/BookReader/utils/classes.js +1 -1
- package/src/BookReader/utils.js +128 -13
- package/src/BookReader.js +559 -1083
- package/src/BookReaderPlugin.js +44 -0
- package/src/assets/icons/magnify-minus.svg +3 -7
- package/src/assets/icons/magnify-plus.svg +3 -7
- package/src/assets/icons/voice.svg +1 -0
- package/src/assets/images/unviewable_page.png +0 -0
- package/src/css/BookReader.scss +1 -5
- package/src/css/_BRBookmarks.scss +1 -1
- package/src/css/_BRComponent.scss +1 -1
- package/src/css/_BRicon.scss +8 -2
- package/src/css/_BRmain.scss +16 -3
- package/src/css/_BRnav.scss +12 -42
- package/src/css/_BRpages.scss +170 -42
- package/src/css/_BRsearch.scss +68 -25
- package/src/css/_BRtoolbar.scss +5 -5
- package/src/css/_TextSelection.scss +87 -27
- package/src/css/_colorbox.scss +2 -2
- package/src/css/_controls.scss +24 -7
- package/src/css/_icons.scss +1 -1
- package/src/ia-bookreader/ia-bookreader.js +224 -0
- package/src/plugins/plugin.archive_analytics.js +84 -78
- package/src/plugins/plugin.autoplay.js +99 -104
- package/src/plugins/plugin.chapters.js +310 -201
- package/src/plugins/plugin.iframe.js +1 -1
- package/src/plugins/plugin.iiif.js +141 -0
- package/src/plugins/plugin.resume.js +53 -50
- package/src/plugins/plugin.text_selection.js +519 -175
- package/src/plugins/plugin.vendor-fullscreen.js +7 -7
- package/src/plugins/search/plugin.search.js +151 -127
- package/src/plugins/search/utils.js +43 -0
- package/src/plugins/search/view.js +37 -59
- package/src/plugins/tts/AbstractTTSEngine.js +75 -45
- package/src/plugins/tts/FestivalTTSEngine.js +21 -31
- package/src/plugins/tts/PageChunk.js +16 -23
- package/src/plugins/tts/PageChunkIterator.js +11 -17
- package/src/plugins/tts/WebTTSEngine.js +126 -84
- package/src/plugins/tts/plugin.tts.js +308 -350
- package/src/plugins/tts/utils.js +29 -26
- package/src/plugins/url/UrlPlugin.js +191 -0
- package/src/plugins/{plugin.url.js → url/plugin.url.js} +47 -18
- package/src/util/browserSniffing.js +33 -1
- package/src/util/docCookies.js +21 -2
- package/src/util/strings.js +1 -0
- package/tests/e2e/README.md +37 -0
- package/tests/e2e/autoplay.test.js +9 -6
- package/tests/e2e/base.test.js +8 -16
- package/tests/e2e/helpers/base.js +55 -50
- package/tests/e2e/helpers/debug.js +1 -1
- package/tests/e2e/helpers/mockSearch.js +19 -22
- package/tests/e2e/helpers/params.js +17 -0
- package/tests/e2e/helpers/rightToLeft.js +8 -14
- package/tests/e2e/helpers/search.js +73 -0
- package/tests/e2e/models/Navigation.js +20 -37
- package/tests/e2e/rightToLeft.test.js +4 -5
- package/tests/e2e/viewmode.test.js +40 -33
- package/tests/jest/BookNavigator/book-navigator.test.js +661 -0
- package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +43 -0
- package/tests/{karma → jest}/BookNavigator/bookmarks/bookmark-edit.test.js +25 -26
- package/tests/{karma → jest}/BookNavigator/bookmarks/bookmarks-list.test.js +41 -42
- package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +45 -0
- package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +67 -0
- package/tests/jest/BookNavigator/downloads/downloads.test.js +53 -0
- package/tests/jest/BookNavigator/search/search-provider.test.js +167 -0
- package/tests/{karma → jest}/BookNavigator/search/search-results.test.js +109 -60
- package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +49 -0
- package/tests/jest/BookNavigator/viewable-files/viewable-files-provider.test.js +80 -0
- package/tests/jest/BookNavigator/visual-adjustments.test.js +200 -0
- package/tests/{BookReader → jest/BookReader}/BookModel.test.js +74 -14
- package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +263 -0
- package/tests/{BookReader → jest/BookReader}/ImageCache.test.js +4 -4
- package/tests/jest/BookReader/Mode1UpLit.test.js +73 -0
- package/tests/jest/BookReader/Mode2Up.test.js +98 -0
- package/tests/jest/BookReader/Mode2UpLit.test.js +190 -0
- package/tests/jest/BookReader/ModeCoordinateSpace.test.js +16 -0
- package/tests/jest/BookReader/ModeSmoothZoom.test.js +218 -0
- package/tests/jest/BookReader/ModeThumb.test.js +71 -0
- package/tests/{BookReader → jest/BookReader}/Navbar/Navbar.test.js +42 -29
- package/tests/jest/BookReader/PageContainer.test.js +238 -0
- package/tests/{BookReader → jest/BookReader}/ReduceSet.test.js +1 -1
- package/tests/{BookReader → jest/BookReader}/Toolbar/Toolbar.test.js +3 -3
- package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +59 -0
- package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +49 -0
- package/tests/jest/BookReader/utils/SelectionObserver.test.js +57 -0
- package/tests/{BookReader → jest/BookReader}/utils/classes.test.js +1 -1
- package/tests/jest/BookReader/utils.test.js +250 -0
- package/tests/jest/BookReader.keyboard.test.js +190 -0
- package/tests/{BookReader.options.test.js → jest/BookReader.options.test.js} +10 -2
- package/tests/{BookReader.test.js → jest/BookReader.test.js} +43 -53
- package/tests/jest/plugins/plugin.archive_analytics.test.js +20 -0
- package/tests/jest/plugins/plugin.autoplay.test.js +35 -0
- package/tests/jest/plugins/plugin.chapters.test.js +193 -0
- package/tests/{plugins → jest/plugins}/plugin.iframe.test.js +4 -4
- package/tests/{plugins → jest/plugins}/plugin.resume.test.js +22 -35
- package/tests/jest/plugins/plugin.text_selection.test.js +316 -0
- package/tests/{plugins → jest/plugins}/plugin.vendor-fullscreen.test.js +2 -2
- package/tests/{plugins → jest/plugins}/search/plugin.search.test.js +19 -47
- package/tests/{plugins → jest/plugins}/search/plugin.search.view.test.js +42 -9
- package/tests/jest/plugins/search/utils.js +25 -0
- package/tests/jest/plugins/search/utils.test.js +29 -0
- package/tests/{plugins → jest/plugins}/tts/AbstractTTSEngine.test.js +30 -10
- package/tests/{plugins → jest/plugins}/tts/FestivalTTSEngine.test.js +4 -4
- package/tests/{plugins → jest/plugins}/tts/PageChunk.test.js +1 -1
- package/tests/{plugins → jest/plugins}/tts/PageChunkIterator.test.js +3 -3
- package/tests/{plugins → jest/plugins}/tts/WebTTSEngine.test.js +65 -13
- package/tests/{plugins → jest/plugins}/tts/utils.test.js +1 -60
- package/tests/jest/plugins/url/UrlPlugin.test.js +198 -0
- package/tests/{plugins → jest/plugins/url}/plugin.url.test.js +57 -18
- package/tests/jest/setup.js +3 -0
- package/tests/{util → jest/util}/browserSniffing.test.js +10 -4
- package/tests/jest/util/docCookies.test.js +24 -0
- package/tests/{util → jest/util}/strings.test.js +1 -1
- package/tests/jest/utils.js +83 -0
- package/webpack.config.js +16 -10
- package/.babelrc +0 -12
- package/.dependabot/config.yml +0 -6
- package/.testcaferc.json +0 -5
- package/BookReader/bookreader-component-bundle.js +0 -1450
- package/BookReader/bookreader-component-bundle.js.LICENSE.txt +0 -38
- package/BookReader/bookreader-component-bundle.js.map +0 -1
- package/BookReader/jquery-1.10.1.js +0 -2
- package/BookReader/jquery-1.10.1.js.LICENSE.txt +0 -24
- package/BookReader/plugins/plugin.menu_toggle.js +0 -2
- package/BookReader/plugins/plugin.menu_toggle.js.map +0 -1
- package/BookReader/plugins/plugin.mobile_nav.js +0 -2
- package/BookReader/plugins/plugin.mobile_nav.js.map +0 -1
- package/BookReaderDemo/BookReaderJSAutoplay.js +0 -56
- package/BookReaderDemo/IIIFBookReader.js +0 -207
- package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
- package/BookReaderDemo/demo-autoplay.html +0 -38
- package/BookReaderDemo/demo-iiif.js +0 -26
- package/BookReaderDemo/demo-plugin-menu-toggle.html +0 -34
- package/karma.conf.js +0 -23
- package/src/BookNavigator/BookModel.js +0 -14
- package/src/BookNavigator/BookNavigator.js +0 -446
- package/src/BookNavigator/assets/book-loader.js +0 -27
- package/src/BookNavigator/br-fullscreen-mgr.js +0 -83
- package/src/BookNavigator/search/a-search-result.js +0 -55
- package/src/BookReader/DebugConsole.js +0 -54
- package/src/BookReaderComponent/BookReaderComponent.js +0 -112
- package/src/ItemNavigator/ItemNavigator.js +0 -376
- package/src/ItemNavigator/providers/sharing.js +0 -29
- package/src/css/_MobileNav.scss +0 -194
- package/src/dragscrollable-br.js +0 -261
- package/src/plugins/menu_toggle/plugin.menu_toggle.js +0 -324
- package/src/plugins/plugin.mobile_nav.js +0 -287
- package/tests/BookReader/BookReaderPublicFunctions.test.js +0 -171
- package/tests/BookReader/DebugConsole.test.js +0 -25
- package/tests/BookReader/Mode1Up.test.js +0 -164
- package/tests/BookReader/Mode2Up.test.js +0 -247
- package/tests/BookReader/PageContainer.test.js +0 -115
- package/tests/BookReader/utils.test.js +0 -109
- package/tests/e2e/helpers/desktopSearch.js +0 -72
- package/tests/e2e/helpers/mobileSearch.js +0 -85
- package/tests/e2e/ia-production/ia-prod-base.js +0 -17
- package/tests/karma/BookNavigator/book-navigator.test.js +0 -132
- package/tests/karma/BookNavigator/search/search-provider.test.js +0 -23
- package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
- package/tests/plugins/menu_toggle/plugin.menu_toggle.test.js +0 -68
- package/tests/plugins/plugin.archive_analytics.test.js +0 -23
- package/tests/plugins/plugin.autoplay.test.js +0 -52
- package/tests/plugins/plugin.chapters.test.js +0 -130
- package/tests/plugins/plugin.mobile_nav.test.js +0 -66
- package/tests/plugins/plugin.text_selection.test.js +0 -203
- package/tests/util/docCookies.test.js +0 -15
- package/tests/utils.js +0 -42
package/src/BookReader.js
CHANGED
@@ -19,31 +19,21 @@ This file is part of BookReader.
|
|
19
19
|
The BookReader source is hosted at http://github.com/internetarchive/bookreader/
|
20
20
|
|
21
21
|
*/
|
22
|
-
// effect.js gives acces to extra easing function (e.g. easeInOutExpo)
|
23
|
-
import 'jquery-ui/ui/effect.js';
|
24
|
-
|
25
22
|
// Needed by touch-punch
|
26
23
|
import 'jquery-ui/ui/widget.js';
|
27
24
|
import 'jquery-ui/ui/widgets/mouse.js';
|
28
25
|
import 'jquery-ui-touch-punch';
|
29
26
|
|
30
|
-
import './dragscrollable-br.js';
|
31
27
|
import PACKAGE_JSON from '../package.json';
|
32
28
|
import * as utils from './BookReader/utils.js';
|
33
29
|
import { exposeOverrideable } from './BookReader/utils/classes.js';
|
34
|
-
import { Navbar
|
35
|
-
import { DEFAULT_OPTIONS } from './BookReader/options.js';
|
30
|
+
import { Navbar } from './BookReader/Navbar/Navbar.js';
|
31
|
+
import { DEFAULT_OPTIONS, OptionsParseError } from './BookReader/options.js';
|
36
32
|
/** @typedef {import('./BookReader/options.js').BookReaderOptions} BookReaderOptions */
|
37
33
|
/** @typedef {import('./BookReader/options.js').ReductionFactor} ReductionFactor */
|
38
34
|
/** @typedef {import('./BookReader/BookModel.js').PageIndex} PageIndex */
|
39
35
|
import { EVENTS } from './BookReader/events.js';
|
40
|
-
import {
|
41
|
-
import {
|
42
|
-
Toolbar,
|
43
|
-
blankInfoDiv,
|
44
|
-
blankShareDiv,
|
45
|
-
createPopup,
|
46
|
-
} from './BookReader/Toolbar/Toolbar.js';
|
36
|
+
import { Toolbar } from './BookReader/Toolbar/Toolbar.js';
|
47
37
|
import { BookModel } from './BookReader/BookModel.js';
|
48
38
|
import { Mode1Up } from './BookReader/Mode1Up.js';
|
49
39
|
import { Mode2Up } from './BookReader/Mode2Up.js';
|
@@ -52,13 +42,9 @@ import { ImageCache } from './BookReader/ImageCache.js';
|
|
52
42
|
import { PageContainer } from './BookReader/PageContainer.js';
|
53
43
|
import { NAMED_REDUCE_SETS } from './BookReader/ReduceSet';
|
54
44
|
|
55
|
-
if (location.toString().indexOf('_debugShowConsole=true') != -1) {
|
56
|
-
$(() => new DebugConsole().init());
|
57
|
-
}
|
58
|
-
|
59
45
|
/**
|
60
46
|
* BookReader
|
61
|
-
* @param {BookReaderOptions}
|
47
|
+
* @param {Partial<BookReaderOptions>} overrides
|
62
48
|
* TODO document all options properties
|
63
49
|
* @constructor
|
64
50
|
*/
|
@@ -76,6 +62,35 @@ BookReader.constMode1up = 1;
|
|
76
62
|
BookReader.constMode2up = 2;
|
77
63
|
/** thumbnails view */
|
78
64
|
BookReader.constModeThumb = 3;
|
65
|
+
|
66
|
+
// Although this can actualy have any BookReaderPlugin subclass as value, we
|
67
|
+
// hardcode the known plugins here for type checking
|
68
|
+
BookReader.PLUGINS = {
|
69
|
+
/** @type {typeof import('./plugins/plugin.archive_analytics.js').ArchiveAnalyticsPlugin | null}*/
|
70
|
+
archiveAnalytics: null,
|
71
|
+
/** @type {typeof import('./plugins/plugin.autoplay.js').AutoplayPlugin | null}*/
|
72
|
+
autoplay: null,
|
73
|
+
/** @type {typeof import('./plugins/plugin.chapters.js').ChaptersPlugin | null}*/
|
74
|
+
chapters: null,
|
75
|
+
/** @type {typeof import('./plugins/plugin.resume.js').ResumePlugin | null}*/
|
76
|
+
resume: null,
|
77
|
+
/** @type {typeof import('./plugins/plugin.text_selection.js').TextSelectionPlugin | null}*/
|
78
|
+
textSelection: null,
|
79
|
+
/** @type {typeof import('./plugins/tts/plugin.tts.js').TtsPlugin | null}*/
|
80
|
+
tts: null,
|
81
|
+
};
|
82
|
+
|
83
|
+
/**
|
84
|
+
* @param {string} pluginName
|
85
|
+
* @param {new (...args: any[]) => import('./BookReaderPlugin.js').BookReaderPlugin} plugin
|
86
|
+
*/
|
87
|
+
BookReader.registerPlugin = function(pluginName, plugin) {
|
88
|
+
if (BookReader.PLUGINS[pluginName]) {
|
89
|
+
console.warn(`Plugin ${pluginName} already registered. Overwriting.`);
|
90
|
+
}
|
91
|
+
BookReader.PLUGINS[pluginName] = plugin;
|
92
|
+
};
|
93
|
+
|
79
94
|
/** image cache */
|
80
95
|
BookReader.imageCache = null;
|
81
96
|
|
@@ -103,6 +118,42 @@ BookReader.prototype.setup = function(options) {
|
|
103
118
|
// Store the options used to setup bookreader
|
104
119
|
this.options = options;
|
105
120
|
|
121
|
+
/** @type {import('@/src/BookNavigator/book-navigator.js').BookNavigator} */
|
122
|
+
this.shell;
|
123
|
+
|
124
|
+
// Construct the usual plugins first to get type hints
|
125
|
+
this._plugins = {
|
126
|
+
archiveAnalytics: BookReader.PLUGINS.archiveAnalytics ? new BookReader.PLUGINS.archiveAnalytics(this) : null,
|
127
|
+
autoplay: BookReader.PLUGINS.autoplay ? new BookReader.PLUGINS.autoplay(this) : null,
|
128
|
+
chapters: BookReader.PLUGINS.chapters ? new BookReader.PLUGINS.chapters(this) : null,
|
129
|
+
resume: BookReader.PLUGINS.resume ? new BookReader.PLUGINS.resume(this) : null,
|
130
|
+
textSelection: BookReader.PLUGINS.textSelection ? new BookReader.PLUGINS.textSelection(this) : null,
|
131
|
+
tts: BookReader.PLUGINS.tts ? new BookReader.PLUGINS.tts(this) : null,
|
132
|
+
};
|
133
|
+
|
134
|
+
// Delete anything that's null
|
135
|
+
for (const [pluginName, plugin] of Object.entries(this._plugins)) {
|
136
|
+
if (!plugin) delete this._plugins[pluginName];
|
137
|
+
}
|
138
|
+
|
139
|
+
// Now construct the rest of the plugins
|
140
|
+
for (const [pluginName, PluginClass] of Object.entries(BookReader.PLUGINS)) {
|
141
|
+
if (this._plugins[pluginName] || !PluginClass) continue;
|
142
|
+
this._plugins[pluginName] = new PluginClass(this);
|
143
|
+
}
|
144
|
+
|
145
|
+
// And call setup on them
|
146
|
+
for (const [pluginName, plugin] of Object.entries(this._plugins)) {
|
147
|
+
try {
|
148
|
+
plugin.setup(this.options.plugins?.[pluginName] ?? {});
|
149
|
+
// Write the options back; this way the plugin is the source of truth,
|
150
|
+
// and BR just contains a reference to it.
|
151
|
+
this.options.plugins[pluginName] = plugin.options;
|
152
|
+
} catch (e) {
|
153
|
+
console.error(`Error setting up plugin ${pluginName}`, e);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
106
157
|
/** @type {number} @deprecated some past iterations set this */
|
107
158
|
this.numLeafs = undefined;
|
108
159
|
|
@@ -152,24 +203,16 @@ BookReader.prototype.setup = function(options) {
|
|
152
203
|
this.ui = options.ui;
|
153
204
|
this.uiAutoHide = options.uiAutoHide;
|
154
205
|
|
155
|
-
this.thumbWidth = 100; // will be overridden during
|
206
|
+
this.thumbWidth = 100; // will be overridden during this._modes.modeThumb.prepare();
|
156
207
|
this.thumbRowBuffer = options.thumbRowBuffer;
|
157
208
|
this.thumbColumns = options.thumbColumns;
|
158
209
|
this.thumbMaxLoading = options.thumbMaxLoading;
|
159
210
|
this.thumbPadding = options.thumbPadding;
|
160
211
|
this.displayedRows = [];
|
161
|
-
|
162
212
|
this.displayedIndices = [];
|
163
|
-
/** @deprecated Unused; will be remove in v5 */
|
164
|
-
this.imgs = {};
|
165
|
-
/** @deprecated No longer used; will be remove in v5 */
|
166
|
-
this.prefetchedImgs = {}; //an object with numeric keys corresponding to page index, reduce
|
167
213
|
|
168
214
|
this.animating = false;
|
169
|
-
this.flipSpeed = options.flipSpeed;
|
170
|
-
this.flipDelay = options.flipDelay;
|
171
|
-
this.twoPagePopUp = null;
|
172
|
-
this.leafEdgeTmp = null;
|
215
|
+
this.flipSpeed = utils.parseAnimationSpeed(options.flipSpeed) || 400;
|
173
216
|
|
174
217
|
/**
|
175
218
|
* Represents the first displayed index
|
@@ -178,8 +221,7 @@ BookReader.prototype.setup = function(options) {
|
|
178
221
|
* @property {number|null} firstIndex
|
179
222
|
*/
|
180
223
|
this.firstIndex = null;
|
181
|
-
this.
|
182
|
-
this.isFullscreenActive = false;
|
224
|
+
this.isFullscreenActive = options.startFullscreen || false;
|
183
225
|
this.lastScroll = null;
|
184
226
|
|
185
227
|
this.showLogo = options.showLogo;
|
@@ -212,26 +254,22 @@ BookReader.prototype.setup = function(options) {
|
|
212
254
|
|
213
255
|
// Assign the data methods
|
214
256
|
this.data = options.data;
|
215
|
-
if (options.getNumLeafs) BookReader.prototype.getNumLeafs = options.getNumLeafs;
|
216
|
-
if (options.getPageWidth) BookReader.prototype.getPageWidth = options.getPageWidth;
|
217
|
-
if (options.getPageHeight) BookReader.prototype.getPageHeight = options.getPageHeight;
|
218
|
-
if (options.getPageURI) BookReader.prototype.getPageURI = options.getPageURI;
|
219
|
-
if (options.getPageSide) BookReader.prototype.getPageSide = options.getPageSide;
|
220
|
-
if (options.getPageNum) BookReader.prototype.getPageNum = options.getPageNum;
|
221
|
-
if (options.getPageProp) BookReader.prototype.getPageProp = options.getPageProp;
|
222
|
-
if (options.getSpreadIndices) BookReader.prototype.getSpreadIndices = options.getSpreadIndices;
|
223
|
-
if (options.leafNumToIndex) BookReader.prototype.leafNumToIndex = options.leafNumToIndex;
|
224
257
|
|
225
258
|
/** @type {{[name: string]: JQuery}} */
|
226
259
|
this.refs = {};
|
227
260
|
|
228
|
-
/**
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
this.
|
233
|
-
|
234
|
-
|
261
|
+
/** The book being displayed in BookReader*/
|
262
|
+
this.book = new BookModel(this);
|
263
|
+
|
264
|
+
if (options.getNumLeafs) this.book.getNumLeafs = options.getNumLeafs.bind(this);
|
265
|
+
if (options.getPageWidth) this.book.getPageWidth = options.getPageWidth.bind(this);
|
266
|
+
if (options.getPageHeight) this.book.getPageHeight = options.getPageHeight.bind(this);
|
267
|
+
if (options.getPageURI) this.book.getPageURI = options.getPageURI.bind(this);
|
268
|
+
if (options.getPageSide) this.book.getPageSide = options.getPageSide.bind(this);
|
269
|
+
if (options.getPageNum) this.book.getPageNum = options.getPageNum.bind(this);
|
270
|
+
if (options.getPageProp) this.book.getPageProp = options.getPageProp.bind(this);
|
271
|
+
if (options.getSpreadIndices) this.book.getSpreadIndices = options.getSpreadIndices.bind(this);
|
272
|
+
if (options.leafNumToIndex) this.book.leafNumToIndex = options.leafNumToIndex.bind(this);
|
235
273
|
|
236
274
|
/**
|
237
275
|
* @private Components are 'subchunks' of bookreader functionality, usually UI related
|
@@ -245,14 +283,14 @@ BookReader.prototype.setup = function(options) {
|
|
245
283
|
};
|
246
284
|
|
247
285
|
this._modes = {
|
248
|
-
mode1Up: new Mode1Up(this, this.
|
249
|
-
mode2Up: new Mode2Up(this, this.
|
250
|
-
modeThumb: new ModeThumb(this, this.
|
286
|
+
mode1Up: new Mode1Up(this, this.book),
|
287
|
+
mode2Up: new Mode2Up(this, this.book),
|
288
|
+
modeThumb: new ModeThumb(this, this.book),
|
251
289
|
};
|
252
290
|
|
253
291
|
/** Stores classes which we want to expose (selectively) some methods as overridable */
|
254
292
|
this._overrideable = {
|
255
|
-
'
|
293
|
+
'book': this.book,
|
256
294
|
'_components.navbar': this._components.navbar,
|
257
295
|
'_components.toolbar': this._components.toolbar,
|
258
296
|
'_modes.mode1Up': this._modes.mode1Up,
|
@@ -261,21 +299,55 @@ BookReader.prototype.setup = function(options) {
|
|
261
299
|
};
|
262
300
|
|
263
301
|
/** Image cache for general image fetching */
|
264
|
-
this.imageCache = new ImageCache(this.
|
302
|
+
this.imageCache = new ImageCache(this.book, {
|
265
303
|
useSrcSet: this.options.useSrcSet,
|
266
304
|
reduceSet: this.reduceSet,
|
305
|
+
renderPageURI: options.renderPageURI.bind(this),
|
267
306
|
});
|
307
|
+
|
308
|
+
/**
|
309
|
+
* Flag if BookReader has "focus" for keyboard shortcuts
|
310
|
+
* Initially true, set to false when:
|
311
|
+
* - BookReader scrolled out of view
|
312
|
+
* Set to true when:
|
313
|
+
* - BookReader scrolled into view
|
314
|
+
*/
|
315
|
+
this.hasKeyFocus = true;
|
268
316
|
};
|
269
317
|
|
270
|
-
/**
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
Object.
|
277
|
-
|
278
|
-
|
318
|
+
/**
|
319
|
+
* Get all the HTML Elements that are being/can be rendered.
|
320
|
+
* Includes cached elements which might be rendered again.
|
321
|
+
*/
|
322
|
+
BookReader.prototype.getActivePageContainerElements = function() {
|
323
|
+
let containerEls = Object.values(this._modes.mode2Up.mode2UpLit.pageContainerCache).map(pc => pc.$container[0])
|
324
|
+
.concat(Object.values(this._modes.mode1Up.mode1UpLit.pageContainerCache).map(pc => pc.$container[0]));
|
325
|
+
if (this.mode == this.constModeThumb) {
|
326
|
+
containerEls = containerEls.concat(this.$('.BRpagecontainer').toArray());
|
327
|
+
}
|
328
|
+
return containerEls;
|
329
|
+
};
|
330
|
+
|
331
|
+
/**
|
332
|
+
* Get the HTML Elements for the rendered page. Note there can be more than one, since
|
333
|
+
* (at least as of writing) different modes can maintain different caches.
|
334
|
+
* @param {PageIndex} pageIndex
|
335
|
+
*/
|
336
|
+
BookReader.prototype.getActivePageContainerElementsForIndex = function(pageIndex) {
|
337
|
+
return [
|
338
|
+
this._modes.mode2Up.mode2UpLit.pageContainerCache[pageIndex]?.$container?.[0],
|
339
|
+
this._modes.mode1Up.mode1UpLit.pageContainerCache[pageIndex]?.$container?.[0],
|
340
|
+
...(this.mode == this.constModeThumb ? this.$(`.pagediv${pageIndex}`).toArray() : []),
|
341
|
+
].filter(x => x);
|
342
|
+
};
|
343
|
+
|
344
|
+
Object.defineProperty(BookReader.prototype, 'activeMode', {
|
345
|
+
/** @return {Mode1Up | Mode2Up | ModeThumb} */
|
346
|
+
get() { return {
|
347
|
+
1: this._modes.mode1Up,
|
348
|
+
2: this._modes.mode2Up,
|
349
|
+
3: this._modes.modeThumb,
|
350
|
+
}[this.mode]; },
|
279
351
|
});
|
280
352
|
|
281
353
|
/**
|
@@ -290,15 +362,15 @@ BookReader.util = utils;
|
|
290
362
|
* @private
|
291
363
|
*/
|
292
364
|
BookReader.prototype.extendParams = function(params, newParams) {
|
293
|
-
|
365
|
+
const modifiedNewParams = $.extend({}, newParams);
|
294
366
|
if ('undefined' != typeof(modifiedNewParams.page)) {
|
295
|
-
|
367
|
+
const pageIndex = this.book.parsePageString(modifiedNewParams.page);
|
296
368
|
if (!isNaN(pageIndex))
|
297
369
|
modifiedNewParams.index = pageIndex;
|
298
370
|
delete modifiedNewParams.page;
|
299
371
|
}
|
300
372
|
$.extend(params, modifiedNewParams);
|
301
|
-
}
|
373
|
+
};
|
302
374
|
|
303
375
|
/**
|
304
376
|
* Parses params from from various initialization contexts (url, cookie, options)
|
@@ -306,7 +378,7 @@ BookReader.prototype.extendParams = function(params, newParams) {
|
|
306
378
|
* @return {object} the parsed params
|
307
379
|
*/
|
308
380
|
BookReader.prototype.initParams = function() {
|
309
|
-
|
381
|
+
const params = {};
|
310
382
|
// Flag initializing for updateFromParams()
|
311
383
|
params.init = true;
|
312
384
|
|
@@ -323,8 +395,8 @@ BookReader.prototype.initParams = function() {
|
|
323
395
|
|
324
396
|
// If we have a title leaf, use that as the default instead of index 0,
|
325
397
|
// but only use as default if book has a few pages
|
326
|
-
if ('undefined' != typeof(this.titleLeaf) && this.
|
327
|
-
params.index = this.
|
398
|
+
if ('undefined' != typeof(this.titleLeaf) && this.book.getNumLeafs() > 2) {
|
399
|
+
params.index = this.book.leafNumToIndex(this.titleLeaf);
|
328
400
|
} else {
|
329
401
|
params.index = 0;
|
330
402
|
}
|
@@ -339,9 +411,9 @@ BookReader.prototype.initParams = function() {
|
|
339
411
|
}
|
340
412
|
|
341
413
|
// Check for Resume plugin
|
342
|
-
if (this.options.
|
414
|
+
if (this._plugins.resume?.options.enabled) {
|
343
415
|
// Check cookies
|
344
|
-
const val = this.getResumeValue();
|
416
|
+
const val = this._plugins.resume.getResumeValue();
|
345
417
|
if (val !== null) {
|
346
418
|
// If page index different from default
|
347
419
|
if (params.index !== val) {
|
@@ -355,7 +427,7 @@ BookReader.prototype.initParams = function() {
|
|
355
427
|
// Check for URL plugin
|
356
428
|
if (this.options.enableUrlPlugin) {
|
357
429
|
// Params explicitly set in URL take precedence over all other methods
|
358
|
-
|
430
|
+
let urlParams = this.paramsFromFragment(this.urlReadFragment());
|
359
431
|
|
360
432
|
// Get params if hash fragment available with 'history' urlMode
|
361
433
|
const hasHashURL = !Object.keys(urlParams).length && this.urlReadHashFragment();
|
@@ -377,7 +449,7 @@ BookReader.prototype.initParams = function() {
|
|
377
449
|
// Check for Search plugin
|
378
450
|
if (this.options.enableSearch) {
|
379
451
|
// Go to first result only if no default or URL page
|
380
|
-
this.options.goToFirstResult = !params.pageFound
|
452
|
+
this.options.goToFirstResult = !params.pageFound;
|
381
453
|
|
382
454
|
// If initialSearchTerm not set
|
383
455
|
if (!this.options.initialSearchTerm) {
|
@@ -389,7 +461,7 @@ BookReader.prototype.initParams = function() {
|
|
389
461
|
} else {
|
390
462
|
// If we have a query string: q=[term]
|
391
463
|
const searchParams = new URLSearchParams(this.readQueryString());
|
392
|
-
const searchTerm = searchParams.get('q')
|
464
|
+
const searchTerm = searchParams.get('q');
|
393
465
|
if (searchTerm) {
|
394
466
|
this.options.initialSearchTerm = utils.decodeURIComponentPlus(searchTerm);
|
395
467
|
}
|
@@ -401,21 +473,21 @@ BookReader.prototype.initParams = function() {
|
|
401
473
|
this.suppressFragmentChange = !params.fragmentChange;
|
402
474
|
|
403
475
|
return params;
|
404
|
-
}
|
476
|
+
};
|
405
477
|
|
406
478
|
/**
|
407
479
|
* Allow mocking of window.location.search
|
408
480
|
*/
|
409
481
|
BookReader.prototype.getLocationSearch = function () {
|
410
482
|
return window.location.search;
|
411
|
-
}
|
483
|
+
};
|
412
484
|
|
413
485
|
/**
|
414
486
|
* Allow mocking of window.location.hash
|
415
487
|
*/
|
416
488
|
BookReader.prototype.getLocationHash = function () {
|
417
489
|
return window.location.hash;
|
418
|
-
}
|
490
|
+
};
|
419
491
|
|
420
492
|
/**
|
421
493
|
* Return URL or fragment querystring
|
@@ -428,37 +500,63 @@ BookReader.prototype.readQueryString = function() {
|
|
428
500
|
const hash = this.getLocationHash();
|
429
501
|
const found = hash.search(/\?\w+=/);
|
430
502
|
return found > -1 ? hash.slice(found) : '';
|
431
|
-
}
|
503
|
+
};
|
432
504
|
|
433
505
|
/**
|
434
506
|
* Determines the initial mode for starting if a mode is not already
|
435
507
|
* present in the params argument
|
436
508
|
* @param {object} params
|
437
|
-
* @return {
|
509
|
+
* @return {1 | 2 | 3} the initial mode
|
438
510
|
*/
|
439
511
|
BookReader.prototype.getInitialMode = function(params) {
|
440
|
-
//
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
) {
|
450
|
-
// In full mode, we set the default based on width
|
451
|
-
nextMode = this.constMode1up;
|
512
|
+
// if mobile breakpoint, we always show this.constMode1up mode
|
513
|
+
const windowWidth = $(window).width();
|
514
|
+
const isMobile = windowWidth && windowWidth <= this.onePageMinBreakpoint;
|
515
|
+
|
516
|
+
let initialMode;
|
517
|
+
if (params.mode) {
|
518
|
+
initialMode = params.mode;
|
519
|
+
} else if (isMobile) {
|
520
|
+
initialMode = this.constMode1up;
|
452
521
|
} else {
|
453
|
-
|
522
|
+
initialMode = this.constMode2up;
|
454
523
|
}
|
455
524
|
|
456
|
-
if (!this.canSwitchToMode(
|
457
|
-
|
525
|
+
if (!this.canSwitchToMode(initialMode)) {
|
526
|
+
initialMode = this.constMode1up;
|
527
|
+
}
|
528
|
+
|
529
|
+
// override defaults mode via `options.defaults` metadata
|
530
|
+
if (this.options.defaults) {
|
531
|
+
try {
|
532
|
+
initialMode = _modeStringToNumber(this.options.defaults);
|
533
|
+
} catch (e) {
|
534
|
+
// Can ignore this error
|
535
|
+
}
|
458
536
|
}
|
459
|
-
|
537
|
+
|
538
|
+
return initialMode;
|
460
539
|
};
|
461
540
|
|
541
|
+
/**
|
542
|
+
* Converts a mode string to a the mode numeric constant
|
543
|
+
* @param {'mode/1up'|'mode/2up'|'mode/thumb'} modeString
|
544
|
+
* @return {1 | 2 | 3}
|
545
|
+
*/
|
546
|
+
export function _modeStringToNumber(modeString) {
|
547
|
+
const MAPPING = {
|
548
|
+
'mode/1up': 1,
|
549
|
+
'mode/2up': 2,
|
550
|
+
'mode/thumb': 3,
|
551
|
+
};
|
552
|
+
|
553
|
+
if (!(modeString in MAPPING)) {
|
554
|
+
throw new OptionsParseError(`Invalid mode string: ${modeString}`);
|
555
|
+
}
|
556
|
+
|
557
|
+
return MAPPING[modeString];
|
558
|
+
}
|
559
|
+
|
462
560
|
/**
|
463
561
|
* This is called by the client to initialize BookReader.
|
464
562
|
* It renders onto the DOM. It should only be called once.
|
@@ -467,7 +565,7 @@ BookReader.prototype.init = function() {
|
|
467
565
|
this.init.initComplete = false;
|
468
566
|
this.pageScale = this.reduce; // preserve current reduce
|
469
567
|
|
470
|
-
|
568
|
+
const params = this.initParams();
|
471
569
|
|
472
570
|
this.firstIndex = params.index ? params.index : 0;
|
473
571
|
|
@@ -497,19 +595,21 @@ BookReader.prototype.init = function() {
|
|
497
595
|
// Explicitly ensure this.mode exists for initNavbar() below
|
498
596
|
this.mode = params.mode;
|
499
597
|
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
598
|
+
// Display Navigation
|
599
|
+
if (this.options.showToolbar) {
|
600
|
+
this.initToolbar(this.mode, this.ui); // Build inside of toolbar div
|
601
|
+
}
|
602
|
+
if (this.options.showNavbar) { // default navigation
|
603
|
+
const $navBar = this.initNavbar();
|
604
|
+
|
605
|
+
// extend navbar with plugins
|
606
|
+
for (const plugin of Object.values(this._plugins)) {
|
607
|
+
plugin.extendNavBar($navBar);
|
508
608
|
}
|
509
609
|
}
|
510
610
|
|
511
611
|
// Switch navbar controls on mobile/desktop
|
512
|
-
this.switchNavbarControls();
|
612
|
+
this._components.navbar.switchNavbarControls();
|
513
613
|
|
514
614
|
this.resizeBRcontainer();
|
515
615
|
this.updateFromParams(params);
|
@@ -521,17 +621,17 @@ BookReader.prototype.init = function() {
|
|
521
621
|
this.setupKeyListeners();
|
522
622
|
|
523
623
|
this.lastScroll = (new Date().getTime());
|
524
|
-
this.refs.$brContainer.
|
624
|
+
this.refs.$brContainer.on('scroll', this, function(e) {
|
525
625
|
// Note, this scroll event fires for both user, and js generated calls
|
526
626
|
// It is functioning in some cases as the primary triggerer for rendering
|
527
627
|
e.data.lastScroll = (new Date().getTime());
|
528
|
-
if (e.data.
|
628
|
+
if (e.data.constModeThumb == e.data.mode) {
|
529
629
|
e.data.drawLeafsThrottled();
|
530
630
|
}
|
531
631
|
});
|
532
632
|
|
533
633
|
if (this.options.autoResize) {
|
534
|
-
$(window).
|
634
|
+
$(window).on('resize', this, function(e) {
|
535
635
|
e.data.resize();
|
536
636
|
});
|
537
637
|
$(window).on("orientationchange", this, function(e) {
|
@@ -548,15 +648,27 @@ BookReader.prototype.init = function() {
|
|
548
648
|
this.suppressFragmentChange = false;
|
549
649
|
}
|
550
650
|
|
651
|
+
if (this.options.startFullscreen) {
|
652
|
+
this.enterFullscreen(true);
|
653
|
+
}
|
654
|
+
|
655
|
+
// Init plugins
|
656
|
+
for (const [pluginName, plugin] of Object.entries(this._plugins)) {
|
657
|
+
try {
|
658
|
+
plugin.init();
|
659
|
+
}
|
660
|
+
catch (e) {
|
661
|
+
console.error(`Error initializing plugin ${pluginName}`, e);
|
662
|
+
}
|
663
|
+
}
|
664
|
+
|
551
665
|
this.init.initComplete = true;
|
552
666
|
this.trigger(BookReader.eventNames.PostInit);
|
553
667
|
|
554
668
|
// Must be called after this.init.initComplete set to true to allow
|
555
669
|
// BookReader.prototype.resize to run.
|
556
|
-
|
557
|
-
|
558
|
-
}
|
559
|
-
}
|
670
|
+
|
671
|
+
};
|
560
672
|
|
561
673
|
/**
|
562
674
|
* @param {EVENTS} name
|
@@ -564,7 +676,6 @@ BookReader.prototype.init = function() {
|
|
564
676
|
*/
|
565
677
|
BookReader.prototype.trigger = function(name, props = this) {
|
566
678
|
const eventName = 'BookReader:' + name;
|
567
|
-
$(document).trigger(eventName, props);
|
568
679
|
|
569
680
|
utils.polyfillCustomEvent(window);
|
570
681
|
window.dispatchEvent(new CustomEvent(eventName, {
|
@@ -572,14 +683,15 @@ BookReader.prototype.trigger = function(name, props = this) {
|
|
572
683
|
composed: true,
|
573
684
|
detail: { props },
|
574
685
|
}));
|
686
|
+
$(document).trigger(eventName, props);
|
575
687
|
};
|
576
688
|
|
577
689
|
BookReader.prototype.bind = function(name, callback) {
|
578
|
-
$(document).
|
690
|
+
$(document).on('BookReader:' + name, callback);
|
579
691
|
};
|
580
692
|
|
581
693
|
BookReader.prototype.unbind = function(name, callback) {
|
582
|
-
$(document).
|
694
|
+
$(document).off('BookReader:' + name, callback);
|
583
695
|
};
|
584
696
|
|
585
697
|
/**
|
@@ -591,135 +703,147 @@ BookReader.prototype.resize = function() {
|
|
591
703
|
this.resizeBRcontainer();
|
592
704
|
|
593
705
|
// Switch navbar controls on mobile/desktop
|
594
|
-
this.switchNavbarControls();
|
706
|
+
this._components.navbar.switchNavbarControls();
|
595
707
|
|
596
708
|
if (this.constMode1up == this.mode) {
|
597
709
|
if (this.onePage.autofit != 'none') {
|
598
|
-
this.
|
710
|
+
this._modes.mode1Up.resizePageView();
|
599
711
|
this.centerPageView();
|
600
|
-
if (this.enableSearch) this.updateSearchHilites(); //deletes highlights but does not call remove()
|
601
712
|
} else {
|
602
713
|
this.centerPageView();
|
603
714
|
this.displayedIndices = [];
|
604
|
-
if (this.enableSearch) this.updateSearchHilites(); //deletes highlights but does not call remove()
|
605
715
|
this.drawLeafsThrottled();
|
606
716
|
}
|
607
717
|
} else if (this.constModeThumb == this.mode) {
|
608
|
-
this.
|
718
|
+
this._modes.modeThumb.prepare();
|
609
719
|
} else {
|
610
|
-
|
611
|
-
if (this.twoPage.autofit) {
|
612
|
-
// most common path, esp. for archive.org books
|
613
|
-
this.prepareTwoPageView();
|
614
|
-
} else {
|
615
|
-
// used when zoomed in
|
616
|
-
// Re-center if the scrollbars have disappeared
|
617
|
-
var center = this.twoPageGetViewCenter();
|
618
|
-
var doRecenter = false;
|
619
|
-
if (this.twoPage.totalWidth < this.refs.$brContainer.prop('clientWidth')) {
|
620
|
-
center.percentageX = 0.5;
|
621
|
-
doRecenter = true;
|
622
|
-
}
|
623
|
-
if (this.twoPage.totalHeight < this.refs.$brContainer.prop('clientHeight')) {
|
624
|
-
center.percentageY = 0.5;
|
625
|
-
doRecenter = true;
|
626
|
-
}
|
627
|
-
if (doRecenter) {
|
628
|
-
this.twoPageCenterView(center.percentageX, center.percentageY);
|
629
|
-
}
|
630
|
-
}
|
720
|
+
this._modes.mode2Up.resizePageView();
|
631
721
|
}
|
632
722
|
this.trigger(BookReader.eventNames.resize);
|
633
723
|
};
|
634
724
|
|
635
725
|
/**
|
636
|
-
* Binds keyboard event listeners
|
726
|
+
* Binds keyboard and keyboard focus event listeners
|
637
727
|
*/
|
638
|
-
BookReader.prototype.setupKeyListeners = function() {
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
var KEY_MINUS = 189; // Chrome
|
652
|
-
var KEY_MINUS_F = 173; // Firefox
|
653
|
-
var KEY_NUMPAD_SUBTRACT = 109;
|
654
|
-
var KEY_EQUAL = 187; // Chrome
|
655
|
-
var KEY_EQUAL_F = 61; // Firefox
|
656
|
-
var KEY_NUMPAD_ADD = 107;
|
657
|
-
|
658
|
-
// We use document here instead of window to avoid a bug in jQuery on IE7
|
659
|
-
$(document).keydown(function(e) {
|
660
|
-
|
661
|
-
// Keyboard navigation
|
662
|
-
if (!self.keyboardNavigationIsDisabled(e)) {
|
663
|
-
switch (e.keyCode) {
|
664
|
-
case KEY_PGUP:
|
665
|
-
case KEY_UP:
|
666
|
-
// In 1up mode page scrolling is handled by browser
|
667
|
-
if (self.constMode2up == self.mode) {
|
668
|
-
e.preventDefault();
|
669
|
-
self.prev();
|
670
|
-
}
|
671
|
-
break;
|
672
|
-
case KEY_DOWN:
|
673
|
-
case KEY_PGDOWN:
|
674
|
-
if (self.constMode2up == self.mode) {
|
675
|
-
e.preventDefault();
|
676
|
-
self.next();
|
728
|
+
BookReader.prototype.setupKeyListeners = function () {
|
729
|
+
|
730
|
+
// Keyboard focus by BookReader in viewport
|
731
|
+
//
|
732
|
+
// Intersection observer and callback sets BookReader keyboard
|
733
|
+
// "focus" flag off when the BookReader is not in the viewport.
|
734
|
+
if (window.IntersectionObserver) {
|
735
|
+
const observer = new IntersectionObserver((entries) => {
|
736
|
+
entries.forEach((entry) => {
|
737
|
+
if (entry.intersectionRatio === 0) {
|
738
|
+
this.hasKeyFocus = false;
|
739
|
+
} else {
|
740
|
+
this.hasKeyFocus = true;
|
677
741
|
}
|
678
|
-
|
679
|
-
|
742
|
+
});
|
743
|
+
}, {
|
744
|
+
root: null,
|
745
|
+
rootMargin: '0px',
|
746
|
+
threshold: [0, 0.05, 1],
|
747
|
+
});
|
748
|
+
observer.observe(this.refs.$br[0]);
|
749
|
+
}
|
750
|
+
|
751
|
+
// Keyboard listeners
|
752
|
+
document.addEventListener('keydown', (e) => {
|
753
|
+
|
754
|
+
// Ignore if BookReader "focus" flag not set
|
755
|
+
if (!this.hasKeyFocus) {
|
756
|
+
return;
|
757
|
+
}
|
758
|
+
|
759
|
+
// Ignore if modifiers are active.
|
760
|
+
if (e.getModifierState('Control') ||
|
761
|
+
e.getModifierState('Alt') ||
|
762
|
+
e.getModifierState('Meta') ||
|
763
|
+
e.getModifierState('Win') /* hack for IE */) {
|
764
|
+
return;
|
765
|
+
}
|
766
|
+
|
767
|
+
// Ignore in input elements
|
768
|
+
if (utils.isInputActive()) {
|
769
|
+
return;
|
770
|
+
}
|
771
|
+
|
772
|
+
// KeyboardEvent code values:
|
773
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values
|
774
|
+
switch (e.key) {
|
775
|
+
|
776
|
+
// Page navigation
|
777
|
+
case "Home":
|
778
|
+
e.preventDefault();
|
779
|
+
this.first();
|
780
|
+
break;
|
781
|
+
case "End":
|
782
|
+
e.preventDefault();
|
783
|
+
this.last();
|
784
|
+
break;
|
785
|
+
case "ArrowDown":
|
786
|
+
case "PageDown":
|
787
|
+
case "Down": // hack for IE and old Gecko
|
788
|
+
// In 1up and thumb mode page scrolling handled by browser
|
789
|
+
if (this.constMode2up === this.mode) {
|
680
790
|
e.preventDefault();
|
681
|
-
|
682
|
-
|
683
|
-
|
791
|
+
this.next();
|
792
|
+
}
|
793
|
+
break;
|
794
|
+
case "ArrowUp":
|
795
|
+
case "PageUp":
|
796
|
+
case "Up": // hack for IE and old Gecko
|
797
|
+
// In 1up and thumb mode page scrolling handled by browser
|
798
|
+
if (this.constMode2up === this.mode) {
|
684
799
|
e.preventDefault();
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
break;
|
693
|
-
case KEY_RIGHT:
|
694
|
-
if (self.constModeThumb != self.mode) {
|
695
|
-
e.preventDefault();
|
696
|
-
self.right();
|
697
|
-
}
|
698
|
-
break;
|
699
|
-
case KEY_MINUS:
|
700
|
-
case KEY_MINUS_F:
|
701
|
-
case KEY_NUMPAD_SUBTRACT:
|
800
|
+
this.prev();
|
801
|
+
}
|
802
|
+
break;
|
803
|
+
case "ArrowLeft":
|
804
|
+
case "Left": // hack for IE and old Gecko
|
805
|
+
// No y-scrolling in thumb mode
|
806
|
+
if (this.constModeThumb != this.mode) {
|
702
807
|
e.preventDefault();
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
808
|
+
this.left();
|
809
|
+
}
|
810
|
+
break;
|
811
|
+
case "ArrowRight":
|
812
|
+
case "Right": // hack for IE and old Gecko
|
813
|
+
// No y-scrolling in thumb mode
|
814
|
+
if (this.constModeThumb != this.mode) {
|
708
815
|
e.preventDefault();
|
709
|
-
|
710
|
-
break;
|
816
|
+
this.right();
|
711
817
|
}
|
818
|
+
break;
|
819
|
+
// Zoom
|
820
|
+
case '-':
|
821
|
+
case 'Subtract':
|
822
|
+
e.preventDefault();
|
823
|
+
this.zoom(-1);
|
824
|
+
break;
|
825
|
+
case '+':
|
826
|
+
case '=':
|
827
|
+
case 'Add':
|
828
|
+
e.preventDefault();
|
829
|
+
this.zoom(1);
|
830
|
+
break;
|
831
|
+
// Fullscreen
|
832
|
+
case 'F':
|
833
|
+
case 'f':
|
834
|
+
e.preventDefault();
|
835
|
+
this.toggleFullscreen();
|
836
|
+
break;
|
712
837
|
}
|
713
838
|
});
|
714
839
|
};
|
715
840
|
|
716
841
|
BookReader.prototype.drawLeafs = function() {
|
717
842
|
if (this.constMode1up == this.mode) {
|
718
|
-
|
719
|
-
|
720
|
-
this.drawLeafsThumbnail();
|
843
|
+
// Not needed for Mode1Up anymore
|
844
|
+
return;
|
721
845
|
} else {
|
722
|
-
this.
|
846
|
+
this.activeMode.drawLeafs();
|
723
847
|
}
|
724
848
|
};
|
725
849
|
|
@@ -728,11 +852,17 @@ BookReader.prototype.drawLeafs = function() {
|
|
728
852
|
* @param {PageIndex} index
|
729
853
|
*/
|
730
854
|
BookReader.prototype._createPageContainer = function(index) {
|
731
|
-
|
855
|
+
const pageContainer = new PageContainer(this.book.getPage(index, false), {
|
732
856
|
isProtected: this.protected,
|
733
857
|
imageCache: this.imageCache,
|
734
|
-
loadingImage: this.imagesBaseURL + 'loading.gif',
|
735
858
|
});
|
859
|
+
|
860
|
+
// Call plugin handlers
|
861
|
+
for (const plugin of Object.values(this._plugins)) {
|
862
|
+
plugin._configurePageContainer(pageContainer);
|
863
|
+
}
|
864
|
+
|
865
|
+
return pageContainer;
|
736
866
|
};
|
737
867
|
|
738
868
|
BookReader.prototype.bindGestures = function(jElement) {
|
@@ -742,8 +872,8 @@ BookReader.prototype.bindGestures = function(jElement) {
|
|
742
872
|
// when you move the book with one finger and then add another
|
743
873
|
// finger to pinch. Gestures are aware of scroll state.
|
744
874
|
|
745
|
-
|
746
|
-
|
875
|
+
const self = this;
|
876
|
+
let numTouches = 1;
|
747
877
|
|
748
878
|
jElement.unbind('touchmove').bind('touchmove', function(e) {
|
749
879
|
if (e.originalEvent.cancelable) numTouches = e.originalEvent.touches.length;
|
@@ -764,60 +894,24 @@ BookReader.prototype.bindGestures = function(jElement) {
|
|
764
894
|
});
|
765
895
|
};
|
766
896
|
|
767
|
-
/** @deprecated Not used outside ModeThumb */
|
768
|
-
BookReader.prototype.drawLeafsThumbnail = ModeThumb.prototype.drawLeafs;
|
769
|
-
exposeOverrideableMethod(ModeThumb, '_modes.modeThumb', 'drawLeafs', 'drawLeafsThumbnail');
|
770
|
-
/** @deprecated Not used outside ModeThumb */
|
771
|
-
BookReader.prototype.lazyLoadThumbnails = ModeThumb.prototype.lazyLoadThumbnails;
|
772
|
-
exposeOverrideableMethod(ModeThumb, '_modes.modeThumb', 'lazyLoadThumbnails', 'lazyLoadThumbnails');
|
773
|
-
BookReader.prototype.lazyLoadImage = ModeThumb.prototype.lazyLoadImage;
|
774
|
-
exposeOverrideableMethod(ModeThumb, '_modes.modeThumb', 'lazyLoadImage', 'lazyLoadImage');
|
775
|
-
/** @deprecated Internal use only */
|
776
|
-
BookReader.prototype.zoomThumb = ModeThumb.prototype.zoom;
|
777
|
-
exposeOverrideableMethod(ModeThumb, '_modes.modeThumb', 'zoom', 'zoomThumb');
|
778
|
-
/** @deprecated Not used outside ModeThumb */
|
779
|
-
BookReader.prototype.getThumbnailWidth = ModeThumb.prototype.getThumbnailWidth;
|
780
|
-
exposeOverrideableMethod(ModeThumb, '_modes.modeThumb', 'getThumbnailWidth', 'getThumbnailWidth');
|
781
|
-
/** @deprecated Not used outside ModeThumb */
|
782
|
-
BookReader.prototype.prepareThumbnailView = ModeThumb.prototype.prepare;
|
783
|
-
exposeOverrideableMethod(ModeThumb, '_modes.modeThumb', 'prepare', 'prepareThumbnailView');
|
784
|
-
|
785
897
|
/**
|
786
898
|
* A throttled version of drawLeafs
|
787
899
|
*/
|
788
900
|
BookReader.prototype.drawLeafsThrottled = utils.throttle(
|
789
901
|
BookReader.prototype.drawLeafs,
|
790
|
-
250 // 250 ms gives quick feedback, but doesn't eat cpu
|
902
|
+
250, // 250 ms gives quick feedback, but doesn't eat cpu
|
791
903
|
);
|
792
904
|
|
793
905
|
/**
|
794
906
|
* @param {number} direction Pass 1 to zoom in, anything else to zoom out
|
795
907
|
*/
|
796
908
|
BookReader.prototype.zoom = function(direction) {
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
this.zoom1up('in');
|
802
|
-
} else {
|
803
|
-
this.zoom1up('out');
|
804
|
-
}
|
805
|
-
break
|
806
|
-
case this.constMode2up:
|
807
|
-
if (direction == 1) {
|
808
|
-
// XXX other cases
|
809
|
-
this.zoom2up('in');
|
810
|
-
} else {
|
811
|
-
this.zoom2up('out');
|
812
|
-
}
|
813
|
-
break
|
814
|
-
case this.constModeThumb:
|
815
|
-
// XXX update zoomThumb for named directions
|
816
|
-
this.zoomThumb(direction);
|
817
|
-
break
|
909
|
+
if (direction == 1) {
|
910
|
+
this.activeMode.zoom('in');
|
911
|
+
} else {
|
912
|
+
this.activeMode.zoom('out');
|
818
913
|
}
|
819
|
-
|
820
|
-
this.textSelectionPlugin?.stopPageFlip(this.refs.$brContainer);
|
914
|
+
this._plugins.textSelection?.stopPageFlip(this.refs.$brContainer);
|
821
915
|
return;
|
822
916
|
};
|
823
917
|
|
@@ -834,19 +928,19 @@ BookReader.prototype.resizeBRcontainer = function(animate) {
|
|
834
928
|
if (animate) {
|
835
929
|
this.refs.$brContainer.animate({
|
836
930
|
top: this.getToolBarHeight(),
|
837
|
-
bottom: this.getFooterHeight()
|
931
|
+
bottom: this.getFooterHeight(),
|
838
932
|
}, this.constResizeAnimationDuration, 'linear');
|
839
933
|
} else {
|
840
934
|
this.refs.$brContainer.css({
|
841
935
|
top: this.getToolBarHeight(),
|
842
|
-
bottom: this.getFooterHeight()
|
936
|
+
bottom: this.getFooterHeight(),
|
843
937
|
});
|
844
938
|
}
|
845
|
-
}
|
939
|
+
};
|
846
940
|
|
847
941
|
BookReader.prototype.centerPageView = function() {
|
848
|
-
|
849
|
-
|
942
|
+
const scrollWidth = this.refs.$brContainer.prop('scrollWidth');
|
943
|
+
const clientWidth = this.refs.$brContainer.prop('clientWidth');
|
850
944
|
if (scrollWidth > clientWidth) {
|
851
945
|
this.refs.$brContainer.prop('scrollLeft', (scrollWidth - clientWidth) / 2);
|
852
946
|
}
|
@@ -934,7 +1028,7 @@ BookReader.prototype._reduceSort = (a, b) => a.reduce - b.reduce;
|
|
934
1028
|
* @return {boolean} Returns true if page could be found, false otherwise.
|
935
1029
|
*/
|
936
1030
|
BookReader.prototype.jumpToPage = function(pageNum) {
|
937
|
-
|
1031
|
+
const pageIndex = this.book.parsePageString(pageNum);
|
938
1032
|
|
939
1033
|
if ('undefined' != typeof(pageIndex)) {
|
940
1034
|
this.jumpToIndex(pageIndex);
|
@@ -950,11 +1044,9 @@ BookReader.prototype.jumpToPage = function(pageNum) {
|
|
950
1044
|
* @param {PageIndex} index
|
951
1045
|
*/
|
952
1046
|
BookReader.prototype._isIndexDisplayed = function(index) {
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
this.currentIndex() == index;
|
957
|
-
}
|
1047
|
+
return this.displayedIndices ? this.displayedIndices.includes(index) :
|
1048
|
+
this.currentIndex() == index;
|
1049
|
+
};
|
958
1050
|
|
959
1051
|
/**
|
960
1052
|
* Changes the current page
|
@@ -965,29 +1057,26 @@ BookReader.prototype._isIndexDisplayed = function(index) {
|
|
965
1057
|
*/
|
966
1058
|
BookReader.prototype.jumpToIndex = function(index, pageX, pageY, noAnimate) {
|
967
1059
|
// Don't jump into specific unviewable page
|
968
|
-
const page = this.
|
1060
|
+
const page = this.book.getPage(index);
|
1061
|
+
|
969
1062
|
if (!page.isViewable && page.unviewablesStart != page.index) {
|
970
1063
|
// If already in unviewable range, jump to end of that range
|
971
1064
|
const alreadyInPreview = this._isIndexDisplayed(page.unviewablesStart);
|
972
|
-
const newIndex = alreadyInPreview ? page.findNext({ combineConsecutiveUnviewables: true })
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
1065
|
+
const newIndex = alreadyInPreview ? page.findNext({ combineConsecutiveUnviewables: true })?.index : page.unviewablesStart;
|
1066
|
+
// Rare, but a book can end on an unviewable page, so this could be undefined
|
1067
|
+
if (typeof newIndex !== 'undefined') {
|
1068
|
+
this.jumpToIndex(newIndex, pageX, pageY, noAnimate);
|
1069
|
+
}
|
1070
|
+
} else {
|
1071
|
+
this.trigger(BookReader.eventNames.stop);
|
977
1072
|
|
978
|
-
|
979
|
-
this._modes.mode2Up.jumpToIndex(index);
|
980
|
-
} else if (this.constModeThumb == this.mode) {
|
981
|
-
this._modes.modeThumb.jumpToIndex(index);
|
982
|
-
} else { // 1up
|
983
|
-
this._modes.mode1Up.jumpToIndex(index, pageX, pageY, noAnimate);
|
1073
|
+
this.activeMode.jumpToIndex(index, pageX, pageY, noAnimate);
|
984
1074
|
}
|
985
1075
|
};
|
986
1076
|
|
987
1077
|
/**
|
988
1078
|
* Return mode or 1up if initial thumb
|
989
1079
|
* @param {number}
|
990
|
-
* @see BookReader.prototype.drawLeafsThumbnail
|
991
1080
|
*/
|
992
1081
|
BookReader.prototype.getPrevReadMode = function(mode) {
|
993
1082
|
if (mode === BookReader.constMode1up || mode === BookReader.constMode2up) {
|
@@ -996,7 +1085,7 @@ BookReader.prototype.getPrevReadMode = function(mode) {
|
|
996
1085
|
// Initial thumb, return 1up
|
997
1086
|
return BookReader.constMode1up;
|
998
1087
|
}
|
999
|
-
}
|
1088
|
+
};
|
1000
1089
|
|
1001
1090
|
/**
|
1002
1091
|
* Switches the mode (eg 1up 2up thumb)
|
@@ -1010,8 +1099,8 @@ BookReader.prototype.switchMode = function(
|
|
1010
1099
|
{
|
1011
1100
|
suppressFragmentChange = false,
|
1012
1101
|
init = false,
|
1013
|
-
pageFound = false
|
1014
|
-
} = {}
|
1102
|
+
pageFound = false,
|
1103
|
+
} = {},
|
1015
1104
|
) {
|
1016
1105
|
// Skip checks before init() complete
|
1017
1106
|
if (this.init.initComplete) {
|
@@ -1024,10 +1113,13 @@ BookReader.prototype.switchMode = function(
|
|
1024
1113
|
}
|
1025
1114
|
|
1026
1115
|
this.trigger(BookReader.eventNames.stop);
|
1027
|
-
if (this.enableSearch) this.removeSearchHilites();
|
1028
1116
|
|
1029
1117
|
this.prevReadMode = this.getPrevReadMode(this.mode);
|
1030
1118
|
|
1119
|
+
if (this.mode != mode) {
|
1120
|
+
this.activeMode.unprepare?.();
|
1121
|
+
}
|
1122
|
+
|
1031
1123
|
this.mode = mode;
|
1032
1124
|
|
1033
1125
|
// reinstate scale if moving from thumbnail view
|
@@ -1040,42 +1132,31 @@ BookReader.prototype.switchMode = function(
|
|
1040
1132
|
|
1041
1133
|
// XXX maybe better to preserve zoom in each mode
|
1042
1134
|
if (this.constMode1up == mode) {
|
1043
|
-
this.
|
1044
|
-
this.reduce = this.quantizeReduce(this.reduce, this.onePage.reductionFactors);
|
1045
|
-
this.prepareOnePageView();
|
1135
|
+
this._modes.mode1Up.prepare();
|
1046
1136
|
} else if (this.constModeThumb == mode) {
|
1047
1137
|
this.reduce = this.quantizeReduce(this.reduce, this.reductionFactors);
|
1048
|
-
this.
|
1138
|
+
this._modes.modeThumb.prepare();
|
1049
1139
|
} else {
|
1050
|
-
|
1051
|
-
// this.twoPage.autofit = null; // Take zoom level from other mode
|
1052
|
-
// spread indices not set, so let's set them
|
1053
|
-
if (init || !pageFound) {
|
1054
|
-
this.setSpreadIndices();
|
1055
|
-
}
|
1056
|
-
|
1057
|
-
this.twoPageCalculateReductionFactors(); // this sets this.twoPage && this.reduce
|
1058
|
-
this.prepareTwoPageView();
|
1059
|
-
this.twoPageCenterView(0.5, 0.5); // $$$ TODO preserve center
|
1140
|
+
this._modes.mode2Up.prepare();
|
1060
1141
|
}
|
1061
1142
|
|
1062
1143
|
if (!(this.suppressFragmentChange || suppressFragmentChange)) {
|
1063
1144
|
this.trigger(BookReader.eventNames.fragmentChange);
|
1064
1145
|
}
|
1065
|
-
|
1146
|
+
const eventName = mode + 'PageViewSelected';
|
1066
1147
|
this.trigger(BookReader.eventNames[eventName]);
|
1067
1148
|
|
1068
|
-
this.
|
1149
|
+
this._plugins.textSelection?.stopPageFlip(this.refs.$brContainer);
|
1069
1150
|
};
|
1070
1151
|
|
1071
1152
|
BookReader.prototype.updateBrClasses = function() {
|
1072
|
-
|
1153
|
+
const modeToClass = {};
|
1073
1154
|
modeToClass[this.constMode1up] = 'BRmode1up';
|
1074
|
-
modeToClass[this.constMode2up] = '
|
1155
|
+
modeToClass[this.constMode2up] = 'BRmode2up';
|
1075
1156
|
modeToClass[this.constModeThumb] = 'BRmodeThumb';
|
1076
1157
|
|
1077
1158
|
this.refs.$br
|
1078
|
-
.removeClass('BRmode1up
|
1159
|
+
.removeClass('BRmode1up BRmode2up BRmodeThumb')
|
1079
1160
|
.addClass(modeToClass[this.mode]);
|
1080
1161
|
|
1081
1162
|
if (this.isFullscreen()) {
|
@@ -1095,31 +1176,30 @@ BookReader.prototype.isFullscreen = function() {
|
|
1095
1176
|
* Toggles fullscreen
|
1096
1177
|
* @param { boolean } bindKeyboardControls
|
1097
1178
|
*/
|
1098
|
-
BookReader.prototype.toggleFullscreen = function(bindKeyboardControls = true) {
|
1179
|
+
BookReader.prototype.toggleFullscreen = async function(bindKeyboardControls = true) {
|
1099
1180
|
if (this.isFullscreen()) {
|
1100
|
-
this.exitFullScreen();
|
1181
|
+
await this.exitFullScreen();
|
1101
1182
|
} else {
|
1102
|
-
this.enterFullscreen(bindKeyboardControls);
|
1183
|
+
await this.enterFullscreen(bindKeyboardControls);
|
1103
1184
|
}
|
1104
1185
|
};
|
1105
1186
|
|
1106
1187
|
/**
|
1107
1188
|
* Enters fullscreen
|
1108
1189
|
* including:
|
1109
|
-
* - animation
|
1110
1190
|
* - binds keyboard controls
|
1111
1191
|
* - fires custom event
|
1112
1192
|
* @param { boolean } bindKeyboardControls
|
1113
1193
|
*/
|
1114
|
-
BookReader.prototype.enterFullscreen = function(bindKeyboardControls = true) {
|
1194
|
+
BookReader.prototype.enterFullscreen = async function(bindKeyboardControls = true) {
|
1195
|
+
this.refs.$br.addClass('BRfullscreenAnimation');
|
1115
1196
|
const currentIndex = this.currentIndex();
|
1116
|
-
this.refs.$brContainer.css('opacity', 0);
|
1117
1197
|
|
1118
1198
|
if (bindKeyboardControls) {
|
1119
1199
|
this._fullscreenCloseHandler = (e) => {
|
1120
1200
|
if (e.keyCode === 27) this.toggleFullscreen();
|
1121
1201
|
};
|
1122
|
-
$(document).keyup
|
1202
|
+
$(document).on("keyup", this._fullscreenCloseHandler);
|
1123
1203
|
}
|
1124
1204
|
|
1125
1205
|
const windowWidth = $(window).width();
|
@@ -1128,15 +1208,28 @@ BookReader.prototype.enterFullscreen = function(bindKeyboardControls = true) {
|
|
1128
1208
|
}
|
1129
1209
|
|
1130
1210
|
this.isFullscreenActive = true;
|
1131
|
-
|
1132
|
-
this.
|
1133
|
-
|
1134
|
-
this.
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1211
|
+
// prioritize class updates so CSS can propagate
|
1212
|
+
this.updateBrClasses();
|
1213
|
+
if (this.activeMode instanceof Mode1Up) {
|
1214
|
+
this.activeMode.mode1UpLit.scale = this.activeMode.mode1UpLit.computeDefaultScale(this.book.getPage(currentIndex));
|
1215
|
+
// Need the new scale to be applied before calling jumpToIndex
|
1216
|
+
this.activeMode.mode1UpLit.requestUpdate();
|
1217
|
+
await this.activeMode.mode1UpLit.updateComplete;
|
1218
|
+
}
|
1219
|
+
this.jumpToIndex(currentIndex);
|
1220
|
+
|
1221
|
+
this._plugins.textSelection?.stopPageFlip(this.refs.$brContainer);
|
1222
|
+
// Add "?view=theater"
|
1223
|
+
this.trigger(BookReader.eventNames.fragmentChange);
|
1224
|
+
// trigger event here, so that animations,
|
1225
|
+
// class updates happen before book-nav relays to web components
|
1139
1226
|
this.trigger(BookReader.eventNames.fullscreenToggled);
|
1227
|
+
|
1228
|
+
// resize book after all events & css updates
|
1229
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
1230
|
+
|
1231
|
+
this.resize();
|
1232
|
+
this.refs.$br.removeClass('BRfullscreenAnimation');
|
1140
1233
|
};
|
1141
1234
|
|
1142
1235
|
/**
|
@@ -1146,27 +1239,35 @@ BookReader.prototype.enterFullscreen = function(bindKeyboardControls = true) {
|
|
1146
1239
|
* - fires custom event
|
1147
1240
|
* @param { boolean } bindKeyboardControls
|
1148
1241
|
*/
|
1149
|
-
BookReader.prototype.exitFullScreen = function() {
|
1150
|
-
this.refs.$
|
1151
|
-
|
1152
|
-
$(document).unbind('keyup', this._fullscreenCloseHandler);
|
1153
|
-
|
1154
|
-
var windowWidth = $(window).width();
|
1242
|
+
BookReader.prototype.exitFullScreen = async function () {
|
1243
|
+
this.refs.$br.addClass('BRfullscreenAnimation');
|
1244
|
+
$(document).off('keyup', this._fullscreenCloseHandler);
|
1155
1245
|
|
1246
|
+
const windowWidth = $(window).width();
|
1156
1247
|
const canShow2up = this.options.controls.twoPage.visible;
|
1157
1248
|
if (canShow2up && (windowWidth <= this.onePageMinBreakpoint)) {
|
1158
1249
|
this.switchMode(this.constMode2up);
|
1159
1250
|
}
|
1160
1251
|
|
1161
1252
|
this.isFullscreenActive = false;
|
1162
|
-
|
1163
|
-
|
1164
|
-
this.refs.$brContainer.animate({opacity: 1}, 'fast', 'linear', () => {
|
1165
|
-
this.resize();
|
1166
|
-
this.animating = false;
|
1167
|
-
});
|
1168
|
-
this.textSelectionPlugin?.stopPageFlip(this.refs.$brContainer);
|
1253
|
+
// Trigger fullscreen event immediately
|
1254
|
+
// so that book-nav can relay to web components
|
1169
1255
|
this.trigger(BookReader.eventNames.fullscreenToggled);
|
1256
|
+
|
1257
|
+
this.updateBrClasses();
|
1258
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
1259
|
+
this.resize();
|
1260
|
+
|
1261
|
+
if (this.activeMode instanceof Mode1Up) {
|
1262
|
+
this.activeMode.mode1UpLit.scale = this.activeMode.mode1UpLit.computeDefaultScale(this.book.getPage(this.currentIndex()));
|
1263
|
+
this.activeMode.mode1UpLit.requestUpdate();
|
1264
|
+
await this.activeMode.mode1UpLit.updateComplete;
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
this._plugins.textSelection?.stopPageFlip(this.refs.$brContainer);
|
1268
|
+
// Remove "?view=theater"
|
1269
|
+
this.trigger(BookReader.eventNames.fragmentChange);
|
1270
|
+
this.refs.$br.removeClass('BRfullscreenAnimation');
|
1170
1271
|
};
|
1171
1272
|
|
1172
1273
|
/**
|
@@ -1180,7 +1281,7 @@ BookReader.prototype.currentIndex = function() {
|
|
1180
1281
|
return this.firstIndex; // $$$ TODO page in center of view would be better
|
1181
1282
|
} else if (this.mode == this.constMode2up) {
|
1182
1283
|
// Only allow indices that are actually present in book
|
1183
|
-
return utils.clamp(this.firstIndex, 0, this.
|
1284
|
+
return utils.clamp(this.firstIndex, 0, this.book.getNumLeafs() - 1);
|
1184
1285
|
} else {
|
1185
1286
|
throw 'currentIndex called for unimplemented mode ' + this.mode;
|
1186
1287
|
}
|
@@ -1195,13 +1296,11 @@ BookReader.prototype.currentIndex = function() {
|
|
1195
1296
|
*/
|
1196
1297
|
BookReader.prototype.updateFirstIndex = function(
|
1197
1298
|
index,
|
1198
|
-
{ suppressFragmentChange = false } = {}
|
1299
|
+
{ suppressFragmentChange = false } = {},
|
1199
1300
|
) {
|
1200
|
-
//
|
1201
|
-
|
1202
|
-
|
1203
|
-
suppressFragmentChange = true;
|
1204
|
-
}
|
1301
|
+
// If there's no change, do nothing
|
1302
|
+
if (this.firstIndex === index) return;
|
1303
|
+
|
1205
1304
|
this.firstIndex = index;
|
1206
1305
|
if (!(this.suppressFragmentChange || suppressFragmentChange)) {
|
1207
1306
|
this.trigger(BookReader.eventNames.fragmentChange);
|
@@ -1212,8 +1311,12 @@ BookReader.prototype.updateFirstIndex = function(
|
|
1212
1311
|
if (this.options.initialSearchTerm && !suppressFragmentChange) {
|
1213
1312
|
this.suppressFragmentChange = false;
|
1214
1313
|
}
|
1215
|
-
|
1216
|
-
this.
|
1314
|
+
|
1315
|
+
this.trigger(BookReader.eventNames.pageChanged);
|
1316
|
+
|
1317
|
+
// event to know if user is actively reading
|
1318
|
+
this.trigger(BookReader.eventNames.userAction);
|
1319
|
+
this._components.navbar.updateNavIndexThrottled(index);
|
1217
1320
|
};
|
1218
1321
|
|
1219
1322
|
/**
|
@@ -1260,24 +1363,42 @@ BookReader.prototype.leftmost = function() {
|
|
1260
1363
|
}
|
1261
1364
|
};
|
1262
1365
|
|
1263
|
-
|
1366
|
+
/**
|
1367
|
+
* @param {object} options
|
1368
|
+
* @param {boolean} [options.triggerStop = true]
|
1369
|
+
* @param {number | 'fast' | 'slow'} [options.flipSpeed]
|
1370
|
+
*/
|
1371
|
+
BookReader.prototype.next = function({
|
1372
|
+
triggerStop = true,
|
1373
|
+
flipSpeed = null,
|
1374
|
+
} = {}) {
|
1264
1375
|
if (this.constMode2up == this.mode) {
|
1265
|
-
this.trigger(BookReader.eventNames.stop);
|
1266
|
-
|
1376
|
+
if (triggerStop) this.trigger(BookReader.eventNames.stop);
|
1377
|
+
flipSpeed = utils.parseAnimationSpeed(flipSpeed) || this.flipSpeed;
|
1378
|
+
this._modes.mode2Up.mode2UpLit.flipAnimation('next', {flipSpeed});
|
1267
1379
|
} else {
|
1268
|
-
if (this.firstIndex < this.
|
1380
|
+
if (this.firstIndex < this.book.getNumLeafs() - 1) {
|
1269
1381
|
this.jumpToIndex(this.firstIndex + 1);
|
1270
1382
|
}
|
1271
1383
|
}
|
1272
1384
|
};
|
1273
1385
|
|
1274
|
-
|
1386
|
+
/**
|
1387
|
+
* @param {object} options
|
1388
|
+
* @param {boolean} [options.triggerStop = true]
|
1389
|
+
* @param {number | 'fast' | 'slow'} [options.flipSpeed]
|
1390
|
+
*/
|
1391
|
+
BookReader.prototype.prev = function({
|
1392
|
+
triggerStop = true,
|
1393
|
+
flipSpeed = null,
|
1394
|
+
} = {}) {
|
1275
1395
|
const isOnFrontPage = this.firstIndex < 1;
|
1276
1396
|
if (isOnFrontPage) return;
|
1277
1397
|
|
1278
1398
|
if (this.constMode2up == this.mode) {
|
1279
|
-
this.trigger(BookReader.eventNames.stop);
|
1280
|
-
|
1399
|
+
if (triggerStop) this.trigger(BookReader.eventNames.stop);
|
1400
|
+
flipSpeed = utils.parseAnimationSpeed(flipSpeed) || this.flipSpeed;
|
1401
|
+
this._modes.mode2Up.mode2UpLit.flipAnimation('prev', {flipSpeed});
|
1281
1402
|
} else {
|
1282
1403
|
if (this.firstIndex >= 1) {
|
1283
1404
|
this.jumpToIndex(this.firstIndex - 1);
|
@@ -1286,257 +1407,13 @@ BookReader.prototype.prev = function() {
|
|
1286
1407
|
};
|
1287
1408
|
|
1288
1409
|
BookReader.prototype.first = function() {
|
1289
|
-
this.jumpToIndex(
|
1410
|
+
this.jumpToIndex(0);
|
1290
1411
|
};
|
1291
1412
|
|
1292
1413
|
BookReader.prototype.last = function() {
|
1293
|
-
this.jumpToIndex(this.
|
1294
|
-
};
|
1295
|
-
|
1296
|
-
/**
|
1297
|
-
* Scrolls down one screen view
|
1298
|
-
*/
|
1299
|
-
BookReader.prototype.scrollDown = function() {
|
1300
|
-
if ($.inArray(this.mode, [this.constMode1up, this.constModeThumb]) >= 0) {
|
1301
|
-
if ( this.mode == this.constMode1up && (this.reduce >= this.onePageGetAutofitHeight()) ) {
|
1302
|
-
// Whole pages are visible, scroll whole page only
|
1303
|
-
return this.next();
|
1304
|
-
}
|
1305
|
-
|
1306
|
-
this.refs.$brContainer.stop(true).animate(
|
1307
|
-
{ scrollTop: '+=' + this._scrollAmount() + 'px'},
|
1308
|
-
400, 'easeInOutExpo'
|
1309
|
-
);
|
1310
|
-
return true;
|
1311
|
-
} else {
|
1312
|
-
return false;
|
1313
|
-
}
|
1314
|
-
};
|
1315
|
-
|
1316
|
-
/**
|
1317
|
-
* Scrolls up one screen view
|
1318
|
-
*/
|
1319
|
-
BookReader.prototype.scrollUp = function() {
|
1320
|
-
if ($.inArray(this.mode, [this.constMode1up, this.constModeThumb]) >= 0) {
|
1321
|
-
if ( this.mode == this.constMode1up && (this.reduce >= this.onePageGetAutofitHeight()) ) {
|
1322
|
-
// Whole pages are visible, scroll whole page only
|
1323
|
-
return this.prev();
|
1324
|
-
}
|
1325
|
-
|
1326
|
-
this.refs.$brContainer.stop(true).animate(
|
1327
|
-
{ scrollTop: '-=' + this._scrollAmount() + 'px'},
|
1328
|
-
400, 'easeInOutExpo'
|
1329
|
-
);
|
1330
|
-
return true;
|
1331
|
-
} else {
|
1332
|
-
return false;
|
1333
|
-
}
|
1334
|
-
};
|
1335
|
-
|
1336
|
-
/**
|
1337
|
-
* The amount to scroll vertically in integer pixels
|
1338
|
-
*/
|
1339
|
-
BookReader.prototype._scrollAmount = function() {
|
1340
|
-
if (this.constMode1up == this.mode) {
|
1341
|
-
// Overlap by % of page size
|
1342
|
-
return parseInt(this.refs.$brContainer.prop('clientHeight') - this._models.book.getPageHeight(this.currentIndex()) / this.reduce * 0.03);
|
1343
|
-
}
|
1344
|
-
|
1345
|
-
return parseInt(0.9 * this.refs.$brContainer.prop('clientHeight'));
|
1414
|
+
this.jumpToIndex(this.book.getNumLeafs() - 1);
|
1346
1415
|
};
|
1347
1416
|
|
1348
|
-
/**
|
1349
|
-
* @deprecated No longer used; will be remove in v5
|
1350
|
-
*/
|
1351
|
-
BookReader.prototype.prefetchImg = async function(index, fetchNow = false) {
|
1352
|
-
console.warn('Call to deprecated function: BookReader.prefetchImg. No-op.');
|
1353
|
-
};
|
1354
|
-
|
1355
|
-
/**
|
1356
|
-
* @deprecated No longer used; will be remove in v5
|
1357
|
-
*/
|
1358
|
-
BookReader.prototype.pruneUnusedImgs = function() {
|
1359
|
-
console.warn('Call to deprecated function: BookReader.pruneUnused. No-op.');
|
1360
|
-
};
|
1361
|
-
|
1362
|
-
/************************/
|
1363
|
-
/** Mode1Up extensions **/
|
1364
|
-
/************************/
|
1365
|
-
/** @deprecated not used outside BookReader */
|
1366
|
-
BookReader.prototype.prepareOnePageView = Mode1Up.prototype.prepare;
|
1367
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'prepare', 'prepareOnePageView');
|
1368
|
-
/** @deprecated not used outside BookReader */
|
1369
|
-
BookReader.prototype.drawLeafsOnePage = Mode1Up.prototype.drawLeafs;
|
1370
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'drawLeafs', 'drawLeafsOnePage');
|
1371
|
-
/** @deprecated not used outside BookReader */
|
1372
|
-
BookReader.prototype.zoom1up = Mode1Up.prototype.zoom;
|
1373
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'zoom', 'zoom1up');
|
1374
|
-
/** @deprecated not used outside Mode1Up */
|
1375
|
-
BookReader.prototype.onePageGetAutofitWidth = Mode1Up.prototype.getAutofitWidth;
|
1376
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'getAutofitWidth', 'onePageGetAutofitWidth');
|
1377
|
-
/** @deprecated not used outside Mode1Up, BookReader */
|
1378
|
-
BookReader.prototype.onePageGetAutofitHeight = Mode1Up.prototype.getAutofitHeight;
|
1379
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'getAutofitHeight', 'onePageGetAutofitHeight');
|
1380
|
-
/** @deprecated not used outside Mode1Up, BookReader */
|
1381
|
-
BookReader.prototype.onePageGetPageTop = Mode1Up.prototype.getPageTop;
|
1382
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'getPageTop', 'onePageGetPageTop');
|
1383
|
-
/** @deprecated not used outside Mode1Up, BookReader */
|
1384
|
-
BookReader.prototype.onePageCalculateReductionFactors = Mode1Up.prototype.calculateReductionFactors;
|
1385
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'calculateReductionFactors', 'onePageCalculateReductionFactors');
|
1386
|
-
/** @deprecated not used outside Mode1Up, BookReader */
|
1387
|
-
BookReader.prototype.resizePageView1up = Mode1Up.prototype.resizePageView;
|
1388
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'resizePageView', 'resizePageView1up');
|
1389
|
-
/** @deprecated not used outside Mode1Up */
|
1390
|
-
BookReader.prototype.onePageCalculateViewDimensions = Mode1Up.prototype.calculateViewDimensions;
|
1391
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'calculateViewDimensions', 'onePageCalculateViewDimensions');
|
1392
|
-
/** @deprecated not used outside Mode1Up */
|
1393
|
-
BookReader.prototype.centerX1up = Mode1Up.prototype.centerX;
|
1394
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'centerX', 'centerX1up');
|
1395
|
-
/** @deprecated not used outside Mode1Up */
|
1396
|
-
BookReader.prototype.centerY1up = Mode1Up.prototype.centerY;
|
1397
|
-
exposeOverrideableMethod(Mode1Up, '_modes.mode1Up', 'centerY', 'centerY1up');
|
1398
|
-
|
1399
|
-
/************************/
|
1400
|
-
/** Mode2Up extensions **/
|
1401
|
-
/************************/
|
1402
|
-
/** @deprecated not used outside Mode2Up */
|
1403
|
-
BookReader.prototype.zoom2up = Mode2Up.prototype.zoom;
|
1404
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'zoom', 'zoom2up');
|
1405
|
-
BookReader.prototype.twoPageGetAutofitReduce = Mode2Up.prototype.getAutofitReduce;
|
1406
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'getAutofitReduce', 'twoPageGetAutofitReduce');
|
1407
|
-
BookReader.prototype.flipBackToIndex = Mode2Up.prototype.flipBackToIndex;
|
1408
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'flipBackToIndex', 'flipBackToIndex');
|
1409
|
-
BookReader.prototype.flipFwdToIndex = Mode2Up.prototype.flipFwdToIndex;
|
1410
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'flipFwdToIndex', 'flipFwdToIndex');
|
1411
|
-
BookReader.prototype.setHilightCss2UP = Mode2Up.prototype.setHilightCss;
|
1412
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'setHilightCss', 'setHilightCss2UP');
|
1413
|
-
/** @deprecated not used outside Mode2Up */
|
1414
|
-
BookReader.prototype.setClickHandler2UP = Mode2Up.prototype.setClickHandler;
|
1415
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'setClickHandler', 'setClickHandler2UP');
|
1416
|
-
/** @deprecated not used outside Mode2Up */
|
1417
|
-
BookReader.prototype.drawLeafsTwoPage = Mode2Up.prototype.drawLeafs;
|
1418
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'drawLeafs', 'drawLeafsTwoPage');
|
1419
|
-
/** @deprecated not used outside BookReader */
|
1420
|
-
BookReader.prototype.prepareTwoPageView = Mode2Up.prototype.prepareTwoPageView;
|
1421
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'prepareTwoPageView', 'prepareTwoPageView');
|
1422
|
-
/** @deprecated not used outside Mode2Up */
|
1423
|
-
BookReader.prototype.prepareTwoPagePopUp = Mode2Up.prototype.preparePopUp;
|
1424
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'preparePopUp', 'prepareTwoPagePopUp');
|
1425
|
-
/** @deprecated not used outside BookReader, Mode2Up */
|
1426
|
-
BookReader.prototype.calculateSpreadSize = Mode2Up.prototype.calculateSpreadSize;
|
1427
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'calculateSpreadSize', 'calculateSpreadSize');
|
1428
|
-
/** @deprecated not used outside BookReader, Mode2Up */
|
1429
|
-
BookReader.prototype.getIdealSpreadSize = Mode2Up.prototype.getIdealSpreadSize;
|
1430
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'getIdealSpreadSize', 'getIdealSpreadSize');
|
1431
|
-
/** @deprecated not used outside BookReader, Mode2Up */
|
1432
|
-
BookReader.prototype.getSpreadSizeFromReduce = Mode2Up.prototype.getSpreadSizeFromReduce;
|
1433
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'getSpreadSizeFromReduce', 'getSpreadSizeFromReduce');
|
1434
|
-
/** @deprecated unused */
|
1435
|
-
BookReader.prototype.twoPageIsZoomedIn = Mode2Up.prototype.isZoomedIn;
|
1436
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'isZoomedIn', 'twoPageIsZoomedIn');
|
1437
|
-
/** @deprecated not used outside BookReader */
|
1438
|
-
BookReader.prototype.twoPageCalculateReductionFactors = Mode2Up.prototype.calculateReductionFactors;
|
1439
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'calculateReductionFactors', 'twoPageCalculateReductionFactors');
|
1440
|
-
/** @deprecated unused */
|
1441
|
-
BookReader.prototype.twoPageSetCursor = Mode2Up.prototype.setCursor;
|
1442
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'setCursor', 'twoPageSetCursor');
|
1443
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1444
|
-
BookReader.prototype.flipLeftToRight = Mode2Up.prototype.flipLeftToRight;
|
1445
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'flipLeftToRight', 'flipLeftToRight');
|
1446
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1447
|
-
BookReader.prototype.flipRightToLeft = Mode2Up.prototype.flipRightToLeft;
|
1448
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'flipRightToLeft', 'flipRightToLeft');
|
1449
|
-
/** @deprecated unused outside Mode2Up */
|
1450
|
-
BookReader.prototype.setMouseHandlers2UP = Mode2Up.prototype.setMouseHandlers;
|
1451
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'setMouseHandlers', 'setMouseHandlers2UP');
|
1452
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1453
|
-
BookReader.prototype.prepareFlipLeftToRight = Mode2Up.prototype.prepareFlipLeftToRight;
|
1454
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'prepareFlipLeftToRight', 'prepareFlipLeftToRight');
|
1455
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1456
|
-
BookReader.prototype.prepareFlipRightToLeft = Mode2Up.prototype.prepareFlipRightToLeft;
|
1457
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'prepareFlipRightToLeft', 'prepareFlipRightToLeft');
|
1458
|
-
/** @deprecated unused outside Mode2Up */
|
1459
|
-
BookReader.prototype.getPageWidth2UP = Mode2Up.prototype.getPageWidth;
|
1460
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'getPageWidth', 'getPageWidth2UP');
|
1461
|
-
/** @deprecated unused outside Mode2Up */
|
1462
|
-
BookReader.prototype.twoPageGutter = Mode2Up.prototype.gutter;
|
1463
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'gutter', 'twoPageGutter');
|
1464
|
-
/** @deprecated unused outside Mode2Up */
|
1465
|
-
BookReader.prototype.twoPageTop = Mode2Up.prototype.top;
|
1466
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'top', 'twoPageTop');
|
1467
|
-
/** @deprecated unused outside Mode2Up */
|
1468
|
-
BookReader.prototype.twoPageCoverWidth = Mode2Up.prototype.coverWidth;
|
1469
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'coverWidth', 'twoPageCoverWidth');
|
1470
|
-
/** @deprecated unused outside Mode2Up */
|
1471
|
-
BookReader.prototype.twoPageGetViewCenter = Mode2Up.prototype.getViewCenter;
|
1472
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'getViewCenter', 'twoPageGetViewCenter');
|
1473
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1474
|
-
BookReader.prototype.twoPageCenterView = Mode2Up.prototype.centerView;
|
1475
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'centerView', 'twoPageCenterView');
|
1476
|
-
/** @deprecated unused outside Mode2Up */
|
1477
|
-
BookReader.prototype.twoPageFlipAreaHeight = Mode2Up.prototype.flipAreaHeight;
|
1478
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'flipAreaHeight', 'twoPageFlipAreaHeight');
|
1479
|
-
/** @deprecated unused outside Mode2Up */
|
1480
|
-
BookReader.prototype.twoPageFlipAreaWidth = Mode2Up.prototype.flipAreaWidth;
|
1481
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'flipAreaWidth', 'twoPageFlipAreaWidth');
|
1482
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1483
|
-
BookReader.prototype.twoPageFlipAreaTop = Mode2Up.prototype.flipAreaTop;
|
1484
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'flipAreaTop', 'twoPageFlipAreaTop');
|
1485
|
-
/** @deprecated unused outside Mode2Up */
|
1486
|
-
BookReader.prototype.twoPageLeftFlipAreaLeft = Mode2Up.prototype.leftFlipAreaLeft;
|
1487
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'leftFlipAreaLeft', 'twoPageLeftFlipAreaLeft');
|
1488
|
-
/** @deprecated unused outside Mode2Up */
|
1489
|
-
BookReader.prototype.twoPageRightFlipAreaLeft = Mode2Up.prototype.rightFlipAreaLeft;
|
1490
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'rightFlipAreaLeft', 'twoPageRightFlipAreaLeft');
|
1491
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1492
|
-
BookReader.prototype.gutterOffsetForIndex = Mode2Up.prototype.gutterOffsetForIndex;
|
1493
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'gutterOffsetForIndex', 'gutterOffsetForIndex');
|
1494
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1495
|
-
BookReader.prototype.leafEdgeWidth = Mode2Up.prototype.leafEdgeWidth;
|
1496
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'leafEdgeWidth', 'leafEdgeWidth');
|
1497
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1498
|
-
BookReader.prototype.jumpIndexForLeftEdgePageX = Mode2Up.prototype.jumpIndexForLeftEdgePageX;
|
1499
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'jumpIndexForLeftEdgePageX', 'jumpIndexForLeftEdgePageX');
|
1500
|
-
/** @deprecated unused outside BookReader, Mode2Up */
|
1501
|
-
BookReader.prototype.jumpIndexForRightEdgePageX = Mode2Up.prototype.jumpIndexForRightEdgePageX;
|
1502
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'jumpIndexForRightEdgePageX', 'jumpIndexForRightEdgePageX');
|
1503
|
-
/** @deprecated unused outside Mode2Up */
|
1504
|
-
BookReader.prototype.prefetch = Mode2Up.prototype.prefetch;
|
1505
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'prefetch', 'prefetch');
|
1506
|
-
/** @deprecated unused outside Mode2Up */
|
1507
|
-
BookReader.prototype.setSpreadIndices = Mode2Up.prototype.setSpreadIndices;
|
1508
|
-
exposeOverrideableMethod(Mode2Up, '_modes.mode2Up', 'setSpreadIndices', 'setSpreadIndices');
|
1509
|
-
/**
|
1510
|
-
* Immediately stop flip animations. Callbacks are triggered.
|
1511
|
-
*/
|
1512
|
-
BookReader.prototype.stopFlipAnimations = function() {
|
1513
|
-
this.trigger(BookReader.eventNames.stop);
|
1514
|
-
|
1515
|
-
// Stop animation, clear queue, trigger callbacks
|
1516
|
-
if (this.leafEdgeTmp) {
|
1517
|
-
$(this.leafEdgeTmp).stop(false, true);
|
1518
|
-
}
|
1519
|
-
jQuery.each(this._modes.mode2Up.pageContainers, function() {
|
1520
|
-
$(this.$container).stop(false, true);
|
1521
|
-
});
|
1522
|
-
|
1523
|
-
// And again since animations also queued in callbacks
|
1524
|
-
if (this.leafEdgeTmp) {
|
1525
|
-
$(this.leafEdgeTmp).stop(false, true);
|
1526
|
-
}
|
1527
|
-
jQuery.each(this._modes.mode2Up.pageContainers, function() {
|
1528
|
-
$(this.$container).stop(false, true);
|
1529
|
-
});
|
1530
|
-
};
|
1531
|
-
|
1532
|
-
/**
|
1533
|
-
* Returns true if keyboard navigation should be disabled for the event
|
1534
|
-
* @param {Event}
|
1535
|
-
* @return {boolean}
|
1536
|
-
*/
|
1537
|
-
BookReader.prototype.keyboardNavigationIsDisabled = function(event) {
|
1538
|
-
return event.target.tagName == "INPUT";
|
1539
|
-
};
|
1540
1417
|
|
1541
1418
|
/**
|
1542
1419
|
* @template TClass extends { br: BookReader }
|
@@ -1560,30 +1437,9 @@ function exposeOverrideableMethod(Class, classKey, method, brMethod = method) {
|
|
1560
1437
|
/***********************/
|
1561
1438
|
/** Navbar extensions **/
|
1562
1439
|
/***********************/
|
1440
|
+
/** This cannot be removed yet because plugin.tts.js overrides it */
|
1563
1441
|
BookReader.prototype.initNavbar = Navbar.prototype.init;
|
1564
1442
|
exposeOverrideableMethod(Navbar, '_components.navbar', 'init', 'initNavbar');
|
1565
|
-
BookReader.prototype.switchNavbarControls = Navbar.prototype.switchNavbarControls;
|
1566
|
-
exposeOverrideableMethod(Navbar, '_components.navbar', 'switchNavbarControls');
|
1567
|
-
BookReader.prototype.updateViewModeButton = Navbar.prototype.updateViewModeButton;
|
1568
|
-
exposeOverrideableMethod(Navbar, '_components.navbar', 'updateViewModeButton');
|
1569
|
-
BookReader.prototype.getNavPageNumString = Navbar.prototype.getNavPageNumString;
|
1570
|
-
exposeOverrideableMethod(Navbar, '_components.navbar', 'getNavPageNumString');
|
1571
|
-
/** @deprecated */
|
1572
|
-
BookReader.prototype.initEmbedNavbar = Navbar.prototype.initEmbed;
|
1573
|
-
exposeOverrideableMethod(Navbar, '_components.navbar', 'initEmbed', 'initEmbedNavbar');
|
1574
|
-
/** @deprecated unused */
|
1575
|
-
BookReader.prototype.getNavPageNumHtml = getNavPageNumHtml;
|
1576
|
-
/** @deprecated unused outside this file */
|
1577
|
-
BookReader.prototype.updateNavPageNum = Navbar.prototype.updateNavPageNum;
|
1578
|
-
exposeOverrideableMethod(Navbar, '_components.navbar', 'updateNavPageNum');
|
1579
|
-
/** @deprecated unused outside this file */
|
1580
|
-
BookReader.prototype.updateNavIndex = Navbar.prototype.updateNavIndex;
|
1581
|
-
exposeOverrideableMethod(Navbar, '_components.navbar', 'updateNavIndex');
|
1582
|
-
/** @deprecated unused outside this file */
|
1583
|
-
BookReader.prototype.updateNavIndexThrottled = utils.throttle(BookReader.prototype.updateNavIndex, 250, false);
|
1584
|
-
/** @deprecated unused */
|
1585
|
-
BookReader.prototype.updateNavIndexDebounced = utils.debounce(BookReader.prototype.updateNavIndex, 500, false);
|
1586
|
-
|
1587
1443
|
|
1588
1444
|
/************************/
|
1589
1445
|
/** Toolbar extensions **/
|
@@ -1598,24 +1454,14 @@ BookReader.prototype.buildInfoDiv = Toolbar.prototype.buildInfoDiv;
|
|
1598
1454
|
exposeOverrideableMethod(Toolbar, '_components.toolbar', 'buildInfoDiv');
|
1599
1455
|
BookReader.prototype.getToolBarHeight = Toolbar.prototype.getToolBarHeight;
|
1600
1456
|
exposeOverrideableMethod(Toolbar, '_components.toolbar', 'getToolBarHeight');
|
1601
|
-
/** @deprecated zoom no longer in toolbar */
|
1602
|
-
BookReader.prototype.updateToolbarZoom = Toolbar.prototype.updateToolbarZoom;
|
1603
|
-
exposeOverrideableMethod(Toolbar, '_components.toolbar', 'updateToolbarZoom');
|
1604
|
-
/** @deprecated unused */
|
1605
|
-
BookReader.prototype.blankInfoDiv = blankInfoDiv;
|
1606
|
-
/** @deprecated unused */
|
1607
|
-
BookReader.prototype.blankShareDiv = blankShareDiv;
|
1608
|
-
/** @deprecated unused */
|
1609
|
-
BookReader.prototype.createPopup = createPopup;
|
1610
1457
|
|
1611
1458
|
/**
|
1612
1459
|
* Bind navigation handlers
|
1613
1460
|
*/
|
1614
1461
|
BookReader.prototype.bindNavigationHandlers = function() {
|
1615
1462
|
const self = this;
|
1463
|
+
const jIcons = this.$('.BRicon');
|
1616
1464
|
|
1617
|
-
// Note the mobile plugin attaches itself to body, so we need to select outside
|
1618
|
-
const jIcons = this.$('.BRicon').add('.BRmobileMenu .BRicon');
|
1619
1465
|
// Map of jIcon class -> click handler
|
1620
1466
|
const navigationControls = {
|
1621
1467
|
book_left: () => {
|
@@ -1626,20 +1472,6 @@ BookReader.prototype.bindNavigationHandlers = function() {
|
|
1626
1472
|
this.trigger(BookReader.eventNames.stop);
|
1627
1473
|
this.right();
|
1628
1474
|
},
|
1629
|
-
book_up: () => {
|
1630
|
-
if ($.inArray(this.mode, [this.constMode1up, this.constModeThumb]) >= 0) {
|
1631
|
-
this.scrollUp();
|
1632
|
-
} else {
|
1633
|
-
this.prev();
|
1634
|
-
}
|
1635
|
-
},
|
1636
|
-
book_down: () => {
|
1637
|
-
if ($.inArray(this.mode, [this.constMode1up, this.constModeThumb]) >= 0) {
|
1638
|
-
this.scrollDown();
|
1639
|
-
} else {
|
1640
|
-
this.next();
|
1641
|
-
}
|
1642
|
-
},
|
1643
1475
|
book_top: this.first.bind(this),
|
1644
1476
|
book_bottom: this.last.bind(this),
|
1645
1477
|
book_leftmost: this.leftmost.bind(this),
|
@@ -1665,7 +1497,7 @@ BookReader.prototype.bindNavigationHandlers = function() {
|
|
1665
1497
|
},
|
1666
1498
|
full: () => {
|
1667
1499
|
if (this.ui == 'embed') {
|
1668
|
-
|
1500
|
+
const url = this.$('.BRembedreturn a').attr('href');
|
1669
1501
|
window.open(url);
|
1670
1502
|
} else {
|
1671
1503
|
this.toggleFullscreen();
|
@@ -1673,29 +1505,31 @@ BookReader.prototype.bindNavigationHandlers = function() {
|
|
1673
1505
|
},
|
1674
1506
|
};
|
1675
1507
|
|
1676
|
-
|
1677
|
-
|
1508
|
+
// custom event for auto-loan-renew in ia-book-actions
|
1509
|
+
// - to know if user is actively reading
|
1510
|
+
this.$('nav.BRcontrols li button').on('click', () => {
|
1511
|
+
this.trigger(BookReader.eventNames.userAction);
|
1678
1512
|
});
|
1679
1513
|
|
1680
1514
|
for (const control in navigationControls) {
|
1681
1515
|
jIcons.filter(`.${control}`).on('click.bindNavigationHandlers', () => {
|
1682
|
-
navigationControls[control]()
|
1516
|
+
navigationControls[control]();
|
1683
1517
|
return false;
|
1684
1518
|
});
|
1685
1519
|
}
|
1686
1520
|
|
1687
|
-
|
1688
|
-
|
1521
|
+
const $brNavCntlBtmEl = this.$('.BRnavCntlBtm');
|
1522
|
+
const $brNavCntlTopEl = this.$('.BRnavCntlTop');
|
1689
1523
|
|
1690
1524
|
this.$('.BRnavCntl').click(
|
1691
1525
|
function() {
|
1692
|
-
|
1526
|
+
const promises = [];
|
1693
1527
|
// TODO don't use magic constants
|
1694
1528
|
// TODO move this to a function
|
1695
1529
|
if ($brNavCntlBtmEl.hasClass('BRdn')) {
|
1696
1530
|
if (self.refs.$BRtoolbar)
|
1697
1531
|
promises.push(self.refs.$BRtoolbar.animate(
|
1698
|
-
{top: self.getToolBarHeight() * -1}
|
1532
|
+
{top: self.getToolBarHeight() * -1},
|
1699
1533
|
).promise());
|
1700
1534
|
promises.push(self.$('.BRfooter').animate({bottom: self.getFooterHeight() * -1}).promise());
|
1701
1535
|
$brNavCntlBtmEl.addClass('BRup').removeClass('BRdn');
|
@@ -1709,7 +1543,7 @@ BookReader.prototype.bindNavigationHandlers = function() {
|
|
1709
1543
|
$brNavCntlBtmEl.addClass('BRdn').removeClass('BRup');
|
1710
1544
|
$brNavCntlTopEl.addClass('BRup').removeClass('BRdn');
|
1711
1545
|
self.$('.BRnavCntlBtm.BRnavCntl').animate({height:'30px'});
|
1712
|
-
self.$('.BRvavCntl').animate({opacity:1})
|
1546
|
+
self.$('.BRvavCntl').animate({opacity:1});
|
1713
1547
|
}
|
1714
1548
|
$.when.apply($, promises).done(function() {
|
1715
1549
|
// Only do full resize in auto mode and need to recalc. size
|
@@ -1725,388 +1559,45 @@ BookReader.prototype.bindNavigationHandlers = function() {
|
|
1725
1559
|
self.resizeBRcontainer();
|
1726
1560
|
}
|
1727
1561
|
});
|
1728
|
-
}
|
1729
|
-
);
|
1730
|
-
$brNavCntlBtmEl.mouseover(function() {
|
1731
|
-
if ($(this).hasClass('BRup')) {
|
1732
|
-
self.$('.BRnavCntl').animate({opacity:1},250);
|
1733
|
-
}
|
1734
|
-
}).mouseleave(function() {
|
1735
|
-
if ($(this).hasClass('BRup')) {
|
1736
|
-
self.$('.BRnavCntl').animate({opacity:.75},250);
|
1737
|
-
}
|
1738
|
-
});
|
1739
|
-
$brNavCntlTopEl.mouseover(function() {
|
1740
|
-
if ($(this).hasClass('BRdn')) {
|
1741
|
-
self.$('.BRnavCntl').animate({opacity:1},250);
|
1742
|
-
}
|
1743
|
-
}).mouseleave(function() {
|
1744
|
-
if ($(this).hasClass('BRdn')) {
|
1745
|
-
self.$('.BRnavCntl').animate({opacity:.75},250);
|
1746
|
-
}
|
1747
|
-
});
|
1748
|
-
|
1749
|
-
this.initSwipeData();
|
1750
|
-
|
1751
|
-
$(document).off('mousemove.navigation', this.el);
|
1752
|
-
$(document).on(
|
1753
|
-
'mousemove.navigation',
|
1754
|
-
this.el,
|
1755
|
-
{ 'br': this },
|
1756
|
-
this.navigationMousemoveHandler
|
1757
|
-
);
|
1758
|
-
|
1759
|
-
$(document).off('mousedown.swipe', '.BRpageimage');
|
1760
|
-
$(document).on(
|
1761
|
-
'mousedown.swipe',
|
1762
|
-
'.BRpageimage',
|
1763
|
-
{ 'br': this },
|
1764
|
-
this.swipeMousedownHandler
|
1765
|
-
);
|
1766
|
-
|
1767
|
-
this.bindMozTouchHandlers();
|
1768
|
-
};
|
1769
|
-
|
1770
|
-
/**
|
1771
|
-
* Unbind navigation handlers
|
1772
|
-
*/
|
1773
|
-
BookReader.prototype.unbindNavigationHandlers = function() {
|
1774
|
-
$(document).off('mousemove.navigation', this.el);
|
1775
|
-
};
|
1776
|
-
|
1777
|
-
/**
|
1778
|
-
* Handle mousemove related to navigation. Bind at #BookReader level to allow autohide.
|
1779
|
-
*/
|
1780
|
-
BookReader.prototype.navigationMousemoveHandler = function(event) {
|
1781
|
-
// $$$ possibly not great to be calling this for every mousemove
|
1782
|
-
if (event.data['br'].uiAutoHide) {
|
1783
|
-
// 77px is an approximate height of the Internet Archive Top Nav
|
1784
|
-
// 75 & 76 (pixels) provide used in this context is checked against the IA top nav height
|
1785
|
-
var navkey = $(document).height() - 75;
|
1786
|
-
if ((event.pageY < 76) || (event.pageY > navkey)) {
|
1787
|
-
// inside or near navigation elements
|
1788
|
-
event.data['br'].hideNavigation();
|
1789
|
-
} else {
|
1790
|
-
event.data['br'].showNavigation();
|
1791
|
-
}
|
1792
|
-
}
|
1793
|
-
};
|
1794
|
-
|
1795
|
-
BookReader.prototype.initSwipeData = function(clientX, clientY) {
|
1796
|
-
/*
|
1797
|
-
* Based on the really quite awesome "Today's Guardian" at http://guardian.gyford.com/
|
1798
|
-
*/
|
1799
|
-
this._swipe = {
|
1800
|
-
mightBeSwiping: false,
|
1801
|
-
didSwipe: false,
|
1802
|
-
mightBeDraggin: false,
|
1803
|
-
didDrag: false,
|
1804
|
-
startTime: (new Date).getTime(),
|
1805
|
-
startX: clientX,
|
1806
|
-
startY: clientY,
|
1807
|
-
lastX: clientX,
|
1808
|
-
lastY: clientY,
|
1809
|
-
deltaX: 0,
|
1810
|
-
deltaY: 0,
|
1811
|
-
deltaT: 0
|
1812
|
-
}
|
1813
|
-
};
|
1814
|
-
|
1815
|
-
BookReader.prototype.swipeMousedownHandler = function(event) {
|
1816
|
-
var self = event.data['br'];
|
1817
|
-
|
1818
|
-
// We should be the last bubble point for the page images
|
1819
|
-
// Disable image drag and select, but keep right-click
|
1820
|
-
if (event.which == 3) {
|
1821
|
-
return !self.protected;
|
1822
|
-
}
|
1823
|
-
|
1824
|
-
$(event.target).bind('mouseout.swipe',
|
1825
|
-
{ 'br': self},
|
1826
|
-
self.swipeMouseupHandler
|
1827
|
-
).bind('mouseup.swipe',
|
1828
|
-
{ 'br': self},
|
1829
|
-
self.swipeMouseupHandler
|
1830
|
-
).bind('mousemove.swipe',
|
1831
|
-
{ 'br': self },
|
1832
|
-
self.swipeMousemoveHandler
|
1562
|
+
},
|
1833
1563
|
);
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
event.preventDefault();
|
1840
|
-
event.returnValue = false;
|
1841
|
-
event.cancelBubble = true;
|
1842
|
-
return false;
|
1843
|
-
};
|
1844
|
-
|
1845
|
-
BookReader.prototype.swipeMousemoveHandler = function(event) {
|
1846
|
-
var self = event.data['br'];
|
1847
|
-
var _swipe = self._swipe;
|
1848
|
-
if (! _swipe.mightBeSwiping) {
|
1849
|
-
return;
|
1850
|
-
}
|
1851
|
-
|
1852
|
-
// Update swipe data
|
1853
|
-
_swipe.deltaX = event.clientX - _swipe.startX;
|
1854
|
-
_swipe.deltaY = event.clientY - _swipe.startY;
|
1855
|
-
_swipe.deltaT = (new Date).getTime() - _swipe.startTime;
|
1856
|
-
|
1857
|
-
var absX = Math.abs(_swipe.deltaX);
|
1858
|
-
var absY = Math.abs(_swipe.deltaY);
|
1859
|
-
|
1860
|
-
// Minimum distance in the amount of tim to trigger the swipe
|
1861
|
-
var minSwipeLength = Math.min(self.refs.$br.width() / 5, 80);
|
1862
|
-
var maxSwipeTime = 400;
|
1863
|
-
|
1864
|
-
// Check for horizontal swipe
|
1865
|
-
if (absX > absY && (absX > minSwipeLength) && _swipe.deltaT < maxSwipeTime) {
|
1866
|
-
_swipe.mightBeSwiping = false; // only trigger once
|
1867
|
-
_swipe.didSwipe = true;
|
1868
|
-
if (self.mode == self.constMode2up) {
|
1869
|
-
if (_swipe.deltaX < 0) {
|
1870
|
-
self.right();
|
1871
|
-
} else {
|
1872
|
-
self.left();
|
1564
|
+
$brNavCntlBtmEl
|
1565
|
+
.on("mouseover", function() {
|
1566
|
+
if ($(this).hasClass('BRup')) {
|
1567
|
+
self.$('.BRnavCntl').animate({opacity:1},250);
|
1873
1568
|
}
|
1874
|
-
}
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
}
|
1885
|
-
}
|
1886
|
-
_swipe.lastX = event.clientX;
|
1887
|
-
_swipe.lastY = event.clientY;
|
1888
|
-
|
1889
|
-
event.preventDefault();
|
1890
|
-
event.returnValue = false;
|
1891
|
-
event.cancelBubble = true;
|
1892
|
-
return false;
|
1893
|
-
};
|
1894
|
-
|
1895
|
-
BookReader.prototype.swipeMouseupHandler = function(event) {
|
1896
|
-
var _swipe = event.data['br']._swipe;
|
1897
|
-
_swipe.mightBeSwiping = false;
|
1898
|
-
_swipe.mightBeDragging = false;
|
1899
|
-
|
1900
|
-
$(event.target).unbind('mouseout.swipe').unbind('mouseup.swipe').unbind('mousemove.swipe');
|
1901
|
-
|
1902
|
-
if (_swipe.didSwipe || _swipe.didDrag) {
|
1903
|
-
// Swallow event if completed swipe gesture
|
1904
|
-
event.preventDefault();
|
1905
|
-
event.returnValue = false;
|
1906
|
-
event.cancelBubble = true;
|
1907
|
-
return false;
|
1908
|
-
}
|
1909
|
-
return true;
|
1910
|
-
};
|
1911
|
-
|
1912
|
-
BookReader.prototype.bindMozTouchHandlers = function() {
|
1913
|
-
var self = this;
|
1914
|
-
|
1915
|
-
// Currently only want touch handlers in 2up
|
1916
|
-
this.refs.$br.bind('MozTouchDown', function(event) {
|
1917
|
-
if (this.mode == self.constMode2up) {
|
1918
|
-
event.preventDefault();
|
1919
|
-
}
|
1920
|
-
})
|
1921
|
-
.bind('MozTouchMove', function(event) {
|
1922
|
-
if (this.mode == self.constMode2up) {
|
1923
|
-
event.preventDefault();
|
1569
|
+
})
|
1570
|
+
.on("mouseleave", function() {
|
1571
|
+
if ($(this).hasClass('BRup')) {
|
1572
|
+
self.$('.BRnavCntl').animate({opacity:.75},250);
|
1573
|
+
}
|
1574
|
+
});
|
1575
|
+
$brNavCntlTopEl
|
1576
|
+
.on("mouseover", function() {
|
1577
|
+
if ($(this).hasClass('BRdn')) {
|
1578
|
+
self.$('.BRnavCntl').animate({opacity:1},250);
|
1924
1579
|
}
|
1925
1580
|
})
|
1926
|
-
.
|
1927
|
-
if (this.
|
1928
|
-
|
1581
|
+
.on("mouseleave", function() {
|
1582
|
+
if ($(this).hasClass('BRdn')) {
|
1583
|
+
self.$('.BRnavCntl').animate({opacity:.75},250);
|
1929
1584
|
}
|
1930
1585
|
});
|
1931
|
-
};
|
1932
|
-
|
1933
|
-
/**
|
1934
|
-
* Returns true if the navigation elements are currently visible
|
1935
|
-
* @return {boolean}
|
1936
|
-
*/
|
1937
|
-
BookReader.prototype.navigationIsVisible = function() {
|
1938
|
-
// $$$ doesn't account for transitioning states, nav must be fully visible to return true
|
1939
|
-
var toolpos = this.refs.$BRtoolbar.position();
|
1940
|
-
var tooltop = toolpos.top;
|
1941
|
-
return tooltop == 0;
|
1942
|
-
};
|
1943
|
-
|
1944
|
-
/**
|
1945
|
-
* Main controller that sets navigation into view.
|
1946
|
-
* Defaults to SHOW the navigation chrome
|
1947
|
-
*/
|
1948
|
-
BookReader.prototype.setNavigationView = function brSetNavigationView(hide) {
|
1949
|
-
var animationLength = this.constNavAnimationDuration;
|
1950
|
-
var animationType = 'linear';
|
1951
|
-
var resizePageContainer = function resizePageContainer () {
|
1952
|
-
/* main page container fills whole container */
|
1953
|
-
if (this.constMode2up !== this.mode) {
|
1954
|
-
var animate = true;
|
1955
|
-
this.resizeBRcontainer(animate);
|
1956
|
-
}
|
1957
|
-
this.trigger(BookReader.eventNames.navToggled);
|
1958
|
-
}.bind(this);
|
1959
|
-
|
1960
|
-
var toolbarHeight = 0;
|
1961
|
-
var navbarHeight = 0;
|
1962
|
-
if (hide) {
|
1963
|
-
toolbarHeight = this.getToolBarHeight() * -1;
|
1964
|
-
navbarHeight = this.getFooterHeight() * -1;
|
1965
|
-
|
1966
|
-
this.refs.$BRtoolbar.addClass('js-menu-hide');
|
1967
|
-
this.refs.$BRfooter.addClass('js-menu-hide');
|
1968
|
-
} else {
|
1969
|
-
this.refs.$BRtoolbar.removeClass('js-menu-hide');
|
1970
|
-
this.refs.$BRfooter.removeClass('js-menu-hide');
|
1971
|
-
}
|
1972
|
-
|
1973
|
-
this.refs.$BRtoolbar.animate(
|
1974
|
-
{ top: toolbarHeight },
|
1975
|
-
animationLength,
|
1976
|
-
animationType,
|
1977
|
-
resizePageContainer
|
1978
|
-
);
|
1979
|
-
this.refs.$BRfooter.animate(
|
1980
|
-
{ bottom: navbarHeight },
|
1981
|
-
animationLength,
|
1982
|
-
animationType,
|
1983
|
-
resizePageContainer
|
1984
|
-
);
|
1985
|
-
};
|
1986
|
-
/**
|
1987
|
-
* Hide navigation elements, if visible
|
1988
|
-
*/
|
1989
|
-
BookReader.prototype.hideNavigation = function() {
|
1990
|
-
// Check if navigation is showing
|
1991
|
-
if (this.navigationIsVisible()) {
|
1992
|
-
var hide = true;
|
1993
|
-
this.setNavigationView(hide);
|
1994
|
-
}
|
1995
|
-
};
|
1996
|
-
|
1997
|
-
/**
|
1998
|
-
* Show navigation elements
|
1999
|
-
*/
|
2000
|
-
BookReader.prototype.showNavigation = function() {
|
2001
|
-
// Check if navigation is hidden
|
2002
|
-
if (!this.navigationIsVisible()) {
|
2003
|
-
this.setNavigationView();
|
2004
|
-
}
|
2005
|
-
};
|
2006
|
-
|
2007
|
-
/**
|
2008
|
-
* Returns the index of the first visible page, dependent on the mode.
|
2009
|
-
* $$$ Currently we cannot display the front/back cover in 2-up and will need to update
|
2010
|
-
* this function when we can as part of https://bugs.launchpad.net/gnubook/+bug/296788
|
2011
|
-
* @return {number}
|
2012
|
-
*/
|
2013
|
-
BookReader.prototype.firstDisplayableIndex = function() {
|
2014
|
-
if (this.mode != this.constMode2up) {
|
2015
|
-
return 0;
|
2016
|
-
}
|
2017
|
-
|
2018
|
-
if ('rl' != this.pageProgression) {
|
2019
|
-
// LTR
|
2020
|
-
if (this._models.book.getPageSide(0) == 'L') {
|
2021
|
-
return 0;
|
2022
|
-
} else {
|
2023
|
-
return -1;
|
2024
|
-
}
|
2025
|
-
} else {
|
2026
|
-
// RTL
|
2027
|
-
if (this._models.book.getPageSide(0) == 'R') {
|
2028
|
-
return 0;
|
2029
|
-
} else {
|
2030
|
-
return -1;
|
2031
|
-
}
|
2032
|
-
}
|
2033
|
-
};
|
2034
1586
|
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
* this function when we can as part of https://bugs.launchpad.net/gnubook/+bug/296788
|
2039
|
-
* @return {number}
|
2040
|
-
*/
|
2041
|
-
BookReader.prototype.lastDisplayableIndex = function() {
|
2042
|
-
|
2043
|
-
var lastIndex = this._models.book.getNumLeafs() - 1;
|
2044
|
-
|
2045
|
-
if (this.mode != this.constMode2up) {
|
2046
|
-
return lastIndex;
|
2047
|
-
}
|
2048
|
-
|
2049
|
-
if ('rl' != this.pageProgression) {
|
2050
|
-
// LTR
|
2051
|
-
if (this._models.book.getPageSide(lastIndex) == 'R') {
|
2052
|
-
return lastIndex;
|
2053
|
-
} else {
|
2054
|
-
return lastIndex + 1;
|
2055
|
-
}
|
2056
|
-
} else {
|
2057
|
-
// RTL
|
2058
|
-
if (this._models.book.getPageSide(lastIndex) == 'L') {
|
2059
|
-
return lastIndex;
|
2060
|
-
} else {
|
2061
|
-
return lastIndex + 1;
|
2062
|
-
}
|
1587
|
+
// Call _bindNavigationHandlers on the plugins
|
1588
|
+
for (const plugin of Object.values(this._plugins)) {
|
1589
|
+
plugin._bindNavigationHandlers();
|
2063
1590
|
}
|
2064
1591
|
};
|
2065
1592
|
|
2066
|
-
|
2067
1593
|
/**************************/
|
2068
1594
|
/** BookModel extensions **/
|
2069
1595
|
/**************************/
|
2070
|
-
|
2071
|
-
|
2072
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getMedianPageSize');
|
2073
|
-
BookReader.prototype._getPageWidth = BookModel.prototype._getPageWidth;
|
2074
|
-
exposeOverrideableMethod(BookModel, '_models.book', '_getPageWidth');
|
2075
|
-
BookReader.prototype._getPageHeight = BookModel.prototype._getPageHeight;
|
2076
|
-
exposeOverrideableMethod(BookModel, '_models.book', '_getPageHeight');
|
2077
|
-
BookReader.prototype.getPageIndex = BookModel.prototype.getPageIndex;
|
2078
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getPageIndex');
|
2079
|
-
/** @deprecated not used outside */
|
2080
|
-
BookReader.prototype.getPageIndices = BookModel.prototype.getPageIndices;
|
2081
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getPageIndices');
|
2082
|
-
BookReader.prototype.getPageName = BookModel.prototype.getPageName;
|
2083
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getPageName');
|
2084
|
-
BookReader.prototype.getNumLeafs = BookModel.prototype.getNumLeafs;
|
2085
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getNumLeafs');
|
2086
|
-
BookReader.prototype.getPageWidth = BookModel.prototype.getPageWidth;
|
2087
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getPageWidth');
|
2088
|
-
BookReader.prototype.getPageHeight = BookModel.prototype.getPageHeight;
|
2089
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getPageHeight');
|
1596
|
+
// Must modify petabox extension, which expects this on the prototype
|
1597
|
+
// before removing.
|
2090
1598
|
BookReader.prototype.getPageURI = BookModel.prototype.getPageURI;
|
2091
|
-
exposeOverrideableMethod(BookModel, '
|
2092
|
-
|
2093
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getPageSide');
|
2094
|
-
BookReader.prototype.getPageNum = BookModel.prototype.getPageNum;
|
2095
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getPageNum');
|
2096
|
-
BookReader.prototype.getPageProp = BookModel.prototype.getPageProp;
|
2097
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getPageProp');
|
2098
|
-
BookReader.prototype.getSpreadIndices = BookModel.prototype.getSpreadIndices;
|
2099
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'getSpreadIndices');
|
2100
|
-
BookReader.prototype.leafNumToIndex = BookModel.prototype.leafNumToIndex;
|
2101
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'leafNumToIndex');
|
2102
|
-
BookReader.prototype.parsePageString = BookModel.prototype.parsePageString;
|
2103
|
-
exposeOverrideableMethod(BookModel, '_models.book', 'parsePageString');
|
2104
|
-
/** @deprecated unused */
|
2105
|
-
BookReader.prototype._getDataFlattened = BookModel.prototype._getDataFlattened;
|
2106
|
-
exposeOverrideableMethod(BookModel, '_models.book', '_getDataFlattened');
|
2107
|
-
/** @deprecated unused */
|
2108
|
-
BookReader.prototype._getDataProp = BookModel.prototype._getDataProp;
|
2109
|
-
exposeOverrideableMethod(BookModel, '_models.book', '_getDataProp');
|
1599
|
+
exposeOverrideableMethod(BookModel, 'book', 'getPageURI');
|
1600
|
+
|
2110
1601
|
|
2111
1602
|
// Parameter related functions
|
2112
1603
|
|
@@ -2125,7 +1616,7 @@ BookReader.prototype.updateFromParams = function(params) {
|
|
2125
1616
|
if (mode) {
|
2126
1617
|
this.switchMode(
|
2127
1618
|
mode,
|
2128
|
-
{ init: init, suppressFragmentChange: !fragmentChange }
|
1619
|
+
{ init: init, suppressFragmentChange: !fragmentChange },
|
2129
1620
|
);
|
2130
1621
|
}
|
2131
1622
|
|
@@ -2137,7 +1628,7 @@ BookReader.prototype.updateFromParams = function(params) {
|
|
2137
1628
|
}
|
2138
1629
|
} else if ('undefined' != typeof(params.page)) {
|
2139
1630
|
// $$$ this assumes page numbers are unique
|
2140
|
-
if (params.page != this.
|
1631
|
+
if (params.page != this.book.getPageNum(this.currentIndex())) {
|
2141
1632
|
this.jumpToPage(params.page);
|
2142
1633
|
}
|
2143
1634
|
}
|
@@ -2171,7 +1662,7 @@ BookReader.prototype.canSwitchToMode = function(mode) {
|
|
2171
1662
|
// check there are enough pages to display
|
2172
1663
|
// $$$ this is a workaround for the mis-feature that we can't display
|
2173
1664
|
// short books in 2up mode
|
2174
|
-
if (this.
|
1665
|
+
if (this.book.getNumLeafs() < 2) {
|
2175
1666
|
return false;
|
2176
1667
|
}
|
2177
1668
|
}
|
@@ -2179,31 +1670,6 @@ BookReader.prototype.canSwitchToMode = function(mode) {
|
|
2179
1670
|
return true;
|
2180
1671
|
};
|
2181
1672
|
|
2182
|
-
|
2183
|
-
/**
|
2184
|
-
* @deprecated. Use PageModel.getURISrcSet. Slated for removal in v5.
|
2185
|
-
* Returns the srcset with correct URIs or void string if out of range
|
2186
|
-
* Also makes the reduce argument optional
|
2187
|
-
* @param {number} index
|
2188
|
-
* @param {number} [reduce]
|
2189
|
-
* @param {number} [rotate]
|
2190
|
-
* @return {string}
|
2191
|
-
*/
|
2192
|
-
BookReader.prototype._getPageURISrcset = function(index, reduce, rotate) {
|
2193
|
-
const page = this._models.book.getPage(index, false);
|
2194
|
-
// Synthesize page
|
2195
|
-
if (!page) return "";
|
2196
|
-
|
2197
|
-
// reduce not passed in
|
2198
|
-
// $$$ this probably won't work for thumbnail mode
|
2199
|
-
if ('undefined' == typeof(reduce)) {
|
2200
|
-
reduce = page.height / this.twoPage.height;
|
2201
|
-
}
|
2202
|
-
|
2203
|
-
return page.getURISrcSet(reduce, rotate);
|
2204
|
-
}
|
2205
|
-
|
2206
|
-
|
2207
1673
|
/**
|
2208
1674
|
* Returns the page URI or transparent image if out of range
|
2209
1675
|
* Also makes the reduce argument optional
|
@@ -2213,7 +1679,7 @@ BookReader.prototype._getPageURISrcset = function(index, reduce, rotate) {
|
|
2213
1679
|
* @return {string}
|
2214
1680
|
*/
|
2215
1681
|
BookReader.prototype._getPageURI = function(index, reduce, rotate) {
|
2216
|
-
const page = this.
|
1682
|
+
const page = this.book.getPage(index, false);
|
2217
1683
|
// Synthesize page
|
2218
1684
|
if (!page) return this.imagesBaseURL + "transparent.png";
|
2219
1685
|
|
@@ -2252,7 +1718,7 @@ BookReader.prototype.showProgressPopup = function(msg, onCloseCallback) {
|
|
2252
1718
|
|
2253
1719
|
const bar = document.createElement("div");
|
2254
1720
|
$(bar).css({
|
2255
|
-
height: '20px'
|
1721
|
+
height: '20px',
|
2256
1722
|
}).prop('className', 'BRprogressbar');
|
2257
1723
|
$(this.popup).append(bar);
|
2258
1724
|
|
@@ -2279,7 +1745,7 @@ BookReader.prototype.initUIStrings = function() {
|
|
2279
1745
|
// the toolbar and nav bar easier
|
2280
1746
|
|
2281
1747
|
// Setup tooltips -- later we could load these from a file for i18n
|
2282
|
-
|
1748
|
+
const titles = {
|
2283
1749
|
'.logo': 'Go to Archive.org', // $$$ update after getting OL record
|
2284
1750
|
'.zoom_in': 'Zoom in',
|
2285
1751
|
'.zoom_out': 'Zoom out',
|
@@ -2295,8 +1761,6 @@ BookReader.prototype.initUIStrings = function() {
|
|
2295
1761
|
'.full': 'Toggle fullscreen',
|
2296
1762
|
'.book_left': 'Flip left',
|
2297
1763
|
'.book_right': 'Flip right',
|
2298
|
-
'.book_up': 'Page up',
|
2299
|
-
'.book_down': 'Page down',
|
2300
1764
|
'.play': 'Play',
|
2301
1765
|
'.pause': 'Pause',
|
2302
1766
|
'.BRdn': 'Show/hide nav bar', // Would have to keep updating on state change to have just "Hide nav bar"
|
@@ -2311,10 +1775,10 @@ BookReader.prototype.initUIStrings = function() {
|
|
2311
1775
|
titles['.book_rightmost'] = 'First page';
|
2312
1776
|
}
|
2313
1777
|
|
2314
|
-
for (
|
1778
|
+
for (const icon in titles) {
|
2315
1779
|
this.$(icon).prop('title', titles[icon]);
|
2316
1780
|
}
|
2317
|
-
}
|
1781
|
+
};
|
2318
1782
|
|
2319
1783
|
/**
|
2320
1784
|
* Reloads images. Useful when some images might have failed.
|
@@ -2322,7 +1786,7 @@ BookReader.prototype.initUIStrings = function() {
|
|
2322
1786
|
BookReader.prototype.reloadImages = function() {
|
2323
1787
|
this.refs.$brContainer.find('img').each(function(index, elem) {
|
2324
1788
|
if (!elem.complete || elem.naturalHeight === 0) {
|
2325
|
-
|
1789
|
+
const src = elem.src;
|
2326
1790
|
elem.src = '';
|
2327
1791
|
setTimeout(function() {
|
2328
1792
|
elem.src = src;
|
@@ -2336,16 +1800,16 @@ BookReader.prototype.reloadImages = function() {
|
|
2336
1800
|
* @return {number}
|
2337
1801
|
*/
|
2338
1802
|
BookReader.prototype.getFooterHeight = function() {
|
2339
|
-
|
1803
|
+
const $heightEl = this.mode == this.constMode2up ? this.refs.$BRfooter : this.refs.$BRnav;
|
2340
1804
|
if ($heightEl && this.refs.$BRfooter) {
|
2341
|
-
|
2342
|
-
|
1805
|
+
const outerHeight = $heightEl.outerHeight();
|
1806
|
+
const bottom = parseInt(this.refs.$BRfooter.css('bottom'));
|
2343
1807
|
if (!isNaN(outerHeight) && !isNaN(bottom)) {
|
2344
1808
|
return outerHeight + bottom;
|
2345
1809
|
}
|
2346
1810
|
}
|
2347
1811
|
return 0;
|
2348
|
-
}
|
1812
|
+
};
|
2349
1813
|
|
2350
1814
|
// Basic Usage built-in Methods (can be overridden through options)
|
2351
1815
|
// This implementation uses options.data value for populating BookReader
|
@@ -2355,10 +1819,11 @@ BookReader.prototype.getFooterHeight = function() {
|
|
2355
1819
|
* @return {Object}
|
2356
1820
|
*/
|
2357
1821
|
BookReader.prototype.paramsFromCurrent = function() {
|
2358
|
-
|
1822
|
+
const params = {};
|
2359
1823
|
|
2360
|
-
|
2361
|
-
|
1824
|
+
// Path params
|
1825
|
+
const index = this.currentIndex();
|
1826
|
+
const pageNum = this.book.getPageNum(index);
|
2362
1827
|
if ((pageNum === 0) || pageNum) {
|
2363
1828
|
params.page = pageNum;
|
2364
1829
|
}
|
@@ -2366,10 +1831,17 @@ BookReader.prototype.paramsFromCurrent = function() {
|
|
2366
1831
|
params.index = index;
|
2367
1832
|
params.mode = this.mode;
|
2368
1833
|
|
1834
|
+
// Unused params
|
2369
1835
|
// $$$ highlight
|
2370
1836
|
// $$$ region
|
2371
1837
|
|
2372
|
-
//
|
1838
|
+
// Querystring params
|
1839
|
+
// View
|
1840
|
+
const fullscreenView = 'theater';
|
1841
|
+
if (this.isFullscreenActive) {
|
1842
|
+
params.view = fullscreenView;
|
1843
|
+
}
|
1844
|
+
// Search
|
2373
1845
|
if (this.enableSearch) {
|
2374
1846
|
params.search = this.searchTerm;
|
2375
1847
|
}
|
@@ -2390,7 +1862,7 @@ BookReader.prototype.paramsFromCurrent = function() {
|
|
2390
1862
|
* @return {Object}
|
2391
1863
|
*/
|
2392
1864
|
BookReader.prototype.paramsFromFragment = function(fragment) {
|
2393
|
-
|
1865
|
+
const params = {};
|
2394
1866
|
|
2395
1867
|
// For backwards compatibility we allow an initial # character
|
2396
1868
|
// (as from window.location.hash) but don't require it
|
@@ -2399,7 +1871,7 @@ BookReader.prototype.paramsFromFragment = function(fragment) {
|
|
2399
1871
|
}
|
2400
1872
|
|
2401
1873
|
// Simple #nn syntax
|
2402
|
-
|
1874
|
+
const oldStyleLeafNum = parseInt( /^\d+$/.exec(fragment) );
|
2403
1875
|
if ( !isNaN(oldStyleLeafNum) ) {
|
2404
1876
|
params.index = oldStyleLeafNum;
|
2405
1877
|
|
@@ -2408,9 +1880,9 @@ BookReader.prototype.paramsFromFragment = function(fragment) {
|
|
2408
1880
|
}
|
2409
1881
|
|
2410
1882
|
// Split into key-value pairs
|
2411
|
-
|
2412
|
-
|
2413
|
-
for (
|
1883
|
+
const urlArray = fragment.split('/');
|
1884
|
+
const urlHash = {};
|
1885
|
+
for (let i = 0; i < urlArray.length; i += 2) {
|
2414
1886
|
urlHash[urlArray[i]] = urlArray[i + 1];
|
2415
1887
|
}
|
2416
1888
|
|
@@ -2426,7 +1898,7 @@ BookReader.prototype.paramsFromFragment = function(fragment) {
|
|
2426
1898
|
// Index and page
|
2427
1899
|
if ('undefined' != typeof(urlHash['page'])) {
|
2428
1900
|
// page was set -- may not be int
|
2429
|
-
params.page = urlHash['page'];
|
1901
|
+
params.page = decodeURIComponent(urlHash['page']);
|
2430
1902
|
}
|
2431
1903
|
|
2432
1904
|
// $$$ process /region
|
@@ -2440,7 +1912,7 @@ BookReader.prototype.paramsFromFragment = function(fragment) {
|
|
2440
1912
|
|
2441
1913
|
// $$$ process /theme
|
2442
1914
|
if (urlHash['theme'] != undefined) {
|
2443
|
-
params.theme = urlHash['theme']
|
1915
|
+
params.theme = urlHash['theme'];
|
2444
1916
|
}
|
2445
1917
|
return params;
|
2446
1918
|
};
|
@@ -2458,11 +1930,10 @@ BookReader.prototype.paramsFromFragment = function(fragment) {
|
|
2458
1930
|
* @return {string}
|
2459
1931
|
*/
|
2460
1932
|
BookReader.prototype.fragmentFromParams = function(params, urlMode = 'hash') {
|
2461
|
-
const separator = '/';
|
2462
1933
|
const fragments = [];
|
2463
1934
|
|
2464
1935
|
if ('undefined' != typeof(params.page)) {
|
2465
|
-
fragments.push('page', params.page);
|
1936
|
+
fragments.push('page', encodeURIComponent(params.page));
|
2466
1937
|
} else {
|
2467
1938
|
if ('undefined' != typeof(params.index)) {
|
2468
1939
|
// Don't have page numbering but we do have the index
|
@@ -2488,15 +1959,18 @@ BookReader.prototype.fragmentFromParams = function(params, urlMode = 'hash') {
|
|
2488
1959
|
|
2489
1960
|
// search
|
2490
1961
|
if (params.search && urlMode === 'hash') {
|
2491
|
-
fragments.push('search', params.search);
|
1962
|
+
fragments.push('search', utils.encodeURIComponentPlus(params.search));
|
2492
1963
|
}
|
2493
1964
|
|
2494
|
-
return
|
1965
|
+
return fragments.join('/');
|
2495
1966
|
};
|
2496
1967
|
|
2497
1968
|
/**
|
2498
1969
|
* Create, update querystring from the params object
|
2499
1970
|
*
|
1971
|
+
* Handles:
|
1972
|
+
* view=
|
1973
|
+
* q=
|
2500
1974
|
* @param {Object} params
|
2501
1975
|
* @param {string} currQueryString
|
2502
1976
|
* @param {string} [urlMode]
|
@@ -2505,30 +1979,32 @@ BookReader.prototype.fragmentFromParams = function(params, urlMode = 'hash') {
|
|
2505
1979
|
BookReader.prototype.queryStringFromParams = function(
|
2506
1980
|
params,
|
2507
1981
|
currQueryString,
|
2508
|
-
urlMode = 'hash'
|
1982
|
+
urlMode = 'hash',
|
2509
1983
|
) {
|
2510
1984
|
const newParams = new URLSearchParams(currQueryString);
|
1985
|
+
|
1986
|
+
if (params.view) {
|
1987
|
+
// Set ?view=theater when fullscreen
|
1988
|
+
newParams.set('view', params.view);
|
1989
|
+
} else {
|
1990
|
+
// Remove
|
1991
|
+
newParams.delete('view');
|
1992
|
+
}
|
1993
|
+
|
2511
1994
|
if (params.search && urlMode === 'history') {
|
2512
|
-
newParams.set('q', params.search)
|
1995
|
+
newParams.set('q', params.search);
|
2513
1996
|
}
|
2514
1997
|
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/toString
|
2515
1998
|
// Note: This method returns the query string without the question mark.
|
2516
1999
|
const result = newParams.toString();
|
2517
2000
|
return result ? '?' + result : '';
|
2518
|
-
}
|
2001
|
+
};
|
2519
2002
|
|
2520
2003
|
/**
|
2521
2004
|
* Helper to select within instance's elements
|
2522
2005
|
*/
|
2523
2006
|
BookReader.prototype.$ = function(selector) {
|
2524
2007
|
return this.refs.$br.find(selector);
|
2525
|
-
}
|
2526
|
-
|
2527
|
-
/**
|
2528
|
-
* Polyfill for deprecated method
|
2529
|
-
*/
|
2530
|
-
jQuery.curCSS = function(element, prop, val) {
|
2531
|
-
return jQuery(element).css(prop, val);
|
2532
2008
|
};
|
2533
2009
|
|
2534
2010
|
window.BookReader = BookReader;
|