forked from internetarchive/bookreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIADemoBr.js
More file actions
146 lines (123 loc) · 4.37 KB
/
IADemoBr.js
File metadata and controls
146 lines (123 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* global BookReader, BookReaderJSIAinit */
import { extraVolOptions, custvolumesManifest } from './ia-multiple-volumes-manifest.js';
/**
* This is how Internet Archive loads bookreader
*/
const urlParams = new URLSearchParams(window.location.search);
function getFromUrl(name, def) {
if (urlParams.has(name)) {
return urlParams.get(name);
} else {
return def;
}
}
const ocaid = urlParams.get('ocaid');
const openFullImmersionTheater = urlParams.get('view') === 'theater';
const ui = urlParams.get('ui');
const searchTerm = urlParams.get('q');
const iaBookReader = document.querySelector('ia-bookreader');
const downloadListWithLCP = [
[
"lcpPDF",
"link to lcp pdf"
],
[
"lcpEPUB",
"link to lcp epub"
]
];
if (openFullImmersionTheater) {
$(document.body).addClass('BRfullscreenActive');
iaBookReader.fullscreen = openFullImmersionTheater;
}
const modal = document.querySelector('modal-manager');
iaBookReader.modal = modal;
// Override options coming from IA
BookReader.optionOverrides.imagesBaseURL = '/BookReader/images/';
const initializeBookReader = (brManifest) => {
console.log('initializeBookReader', brManifest);
const options = {
el: '#BookReader',
/* Url plugin - IA uses History mode for URL */
// commenting these out as demo uses hash mode
// keeping them here for reference
// urlHistoryBasePath: `/details/{$ocaid}/`,
// resumeCookiePath: `/details/{$ocaid}/`,
// urlMode: 'history',
// Only reflect these params onto the URL
// urlTrackedParams: ['page', 'search', 'mode'],
/* End url plugin */
enableBookTitleLink: false,
bookUri: `https://archive.org/details/${ocaid}`,
bookUrlText: null,
startFullscreen: openFullImmersionTheater,
// leaving this option commented out bc we change given user agent on archive.org
// onePage: { autofit: <?=json_encode($this->ios ? 'width' : 'auto')?> },
showToolbar: getFromUrl('options.showToolbar', 'false') === 'true',
/* Multiple volumes */
// To show multiple volumes:
enableMultipleBooks: false, // turn this on
multipleBooksList: [], // populate this // TODO: get sample blob and tie into demo
/* End multiple volumes */
enableBookmarks: true, // turn this on
enableFSLogoShortcut: true,
plugins: {
search: {
initialSearchTerm: searchTerm ? searchTerm : '',
},
},
};
// we want to show item as embedded when ?ui=embed is in URI
if (ui === 'embed') {
options.mode = 1;
options.ui = 'embed';
}
// we expect this at the global level
BookReaderJSIAinit(brManifest.data, options);
const isRestricted = brManifest.data.isRestricted;
window.dispatchEvent(new CustomEvent('contextmenu', { detail: { isRestricted } }));
};
window.initializeBookReader = initializeBookReader;
const showLCP = document.querySelector('#show-lcp');
showLCP.addEventListener('click', async () => {
const iaBr = document.querySelector('ia-bookreader');
iaBr.downloadableTypes = downloadListWithLCP;
iaBr.updateMenuContents();
await iaBr.updateComplete;
});
const multiVolume = document.querySelector('#multi-volume');
multiVolume.addEventListener('click', () => {
// remove everything
$('#BookReader').empty();
delete window.br;
// and re-mount with a new book
BookReaderJSIAinit(custvolumesManifest, extraVolOptions);
});
const fetchBookManifestAndInitializeBookreader = async (iaMetadata) => {
document.querySelector('input[name="itemMD"]').checked = true;
iaBookReader.item = iaMetadata;
const jsiaParams = {
format: 'jsonp',
itemPath: iaMetadata.dir,
id: iaMetadata.metadata.identifier,
server: iaMetadata.server,
};
const jp2File = iaMetadata.files.find(f => f.name.endsWith('_jp2.zip'))
if (jp2File) {
jsiaParams.subPrefix = jp2File.name.replace('_jp2.zip', '');
}
const iaManifestUrl = `https://${iaMetadata.server}/BookReader/BookReaderJSIA.php?${
new URLSearchParams(jsiaParams)
}`;
const manifest = await fetch(iaManifestUrl).then(response => response.json());
document.querySelector('input[name="bookManifest"]').checked = true;
initializeBookReader(manifest);
};
// Temp; Circumvent bug in BookReaderJSIA code
window.Sentry = null;
window.logError = function(e) {
console.error(e);
};
fetch(`https://archive.org/metadata/${ocaid}`)
.then(response => response.json())
.then(iaMetadata => fetchBookManifestAndInitializeBookreader(iaMetadata));