-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathExtension.ts
172 lines (138 loc) Β· 6.57 KB
/
Extension.ts
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { ExternalResourceType } from '@iiif/vocabulary';
import { Canvas, LanguageMap, Thumb } from 'manifesto.js';
import {BaseEvents} from "../../modules/uv-shared-module/BaseEvents";
import {BaseExtension} from "../../modules/uv-shared-module/BaseExtension";
import {Bookmark} from "../../modules/uv-shared-module/Bookmark";
import {DownloadDialogue} from "./DownloadDialogue";
import {FooterPanel} from "../../modules/uv-shared-module/FooterPanel";
import {IPDFExtension} from "./IPDFExtension";
import {MoreInfoRightPanel} from "../../modules/uv-moreinforightpanel-module/MoreInfoRightPanel";
import {PDFCenterPanel} from "../../modules/uv-pdfcenterpanel-module/PDFCenterPanel";
import {PDFHeaderPanel} from "../../modules/uv-pdfheaderpanel-module/PDFHeaderPanel";
import {ResourcesLeftPanel} from "../../modules/uv-resourcesleftpanel-module/ResourcesLeftPanel";
import {SettingsDialogue} from "./SettingsDialogue";
import {ShareDialogue} from "./ShareDialogue";
export class Extension extends BaseExtension implements IPDFExtension {
$downloadDialogue: JQuery;
$shareDialogue: JQuery;
$helpDialogue: JQuery;
$settingsDialogue: JQuery;
centerPanel: PDFCenterPanel;
downloadDialogue: DownloadDialogue;
shareDialogue: ShareDialogue;
footerPanel: FooterPanel;
headerPanel: PDFHeaderPanel;
leftPanel: ResourcesLeftPanel;
rightPanel: MoreInfoRightPanel;
settingsDialogue: SettingsDialogue;
create(): void {
requirejs.config({paths: {'pdfjs-dist/build/pdf.combined': this.data.root + '/lib/' + 'pdf.combined'}});
super.create();
this.component.subscribe(BaseEvents.CANVAS_INDEX_CHANGED, (canvasIndex: number) => {
this.viewCanvas(canvasIndex);
});
this.component.subscribe(BaseEvents.THUMB_SELECTED, (thumb: Thumb) => {
this.component.publish(BaseEvents.CANVAS_INDEX_CHANGED, thumb.index);
});
this.component.subscribe(BaseEvents.LEFTPANEL_EXPAND_FULL_START, () => {
this.shell.$centerPanel.hide();
this.shell.$rightPanel.hide();
});
this.component.subscribe(BaseEvents.LEFTPANEL_COLLAPSE_FULL_FINISH, () => {
this.shell.$centerPanel.show();
this.shell.$rightPanel.show();
this.resize();
});
this.component.subscribe(BaseEvents.SHOW_OVERLAY, () => {
if (this.IsOldIE()) {
this.centerPanel.$element.hide();
}
});
this.component.subscribe(BaseEvents.HIDE_OVERLAY, () => {
if (this.IsOldIE()) {
this.centerPanel.$element.show();
}
});
this.component.subscribe(BaseEvents.EXIT_FULLSCREEN, () => {
setTimeout(() => {
this.resize();
}, 10); // allow time to exit full screen, then resize
});
}
render(): void {
super.render();
}
IsOldIE(): boolean {
const browser: string = window.browserDetect.browser;
const version: number = window.browserDetect.version;
if (browser === 'Explorer' && version <= 9) return true;
return false;
}
isHeaderPanelEnabled(): boolean {
return super.isHeaderPanelEnabled() && Utils.Bools.getBool(this.data.config.options.usePdfJs, true);
}
createModules(): void{
super.createModules();
if (this.isHeaderPanelEnabled()) {
this.headerPanel = new PDFHeaderPanel(this.shell.$headerPanel);
} else {
this.shell.$headerPanel.hide();
}
if (this.isLeftPanelEnabled()) {
this.leftPanel = new ResourcesLeftPanel(this.shell.$leftPanel);
}
this.centerPanel = new PDFCenterPanel(this.shell.$centerPanel);
if (this.isRightPanelEnabled()) {
this.rightPanel = new MoreInfoRightPanel(this.shell.$rightPanel);
}
if (this.isFooterPanelEnabled()) {
this.footerPanel = new FooterPanel(this.shell.$footerPanel);
} else {
this.shell.$footerPanel.hide();
}
this.$downloadDialogue = $('<div class="overlay download" aria-hidden="true"></div>');
this.shell.$overlays.append(this.$downloadDialogue);
this.downloadDialogue = new DownloadDialogue(this.$downloadDialogue);
this.$shareDialogue = $('<div class="overlay share" aria-hidden="true"></div>');
this.shell.$overlays.append(this.$shareDialogue);
this.shareDialogue = new ShareDialogue(this.$shareDialogue);
this.$settingsDialogue = $('<div class="overlay settings" aria-hidden="true"></div>');
this.shell.$overlays.append(this.$settingsDialogue);
this.settingsDialogue = new SettingsDialogue(this.$settingsDialogue);
if (this.isLeftPanelEnabled()) {
this.leftPanel.init();
}
if (this.isRightPanelEnabled()) {
this.rightPanel.init();
}
}
isLeftPanelEnabled(): boolean {
return Utils.Bools.getBool(this.data.config.options.leftPanelEnabled, true)
&& ((this.helper.isMultiCanvas() || this.helper.isMultiSequence()) || this.helper.hasResources());
}
bookmark() : void {
super.bookmark();
const canvas: Canvas = this.helper.getCurrentCanvas();
const bookmark: Bookmark = new Bookmark();
bookmark.index = this.helper.canvasIndex;
bookmark.label = <string>LanguageMap.getValue(canvas.getLabel());
bookmark.thumb = canvas.getProperty('thumbnail');
bookmark.title = this.helper.getLabel();
bookmark.trackingLabel = window.trackingLabel;
bookmark.type = ExternalResourceType.DOCUMENT.toString();
this.fire(BaseEvents.BOOKMARK, bookmark);
}
dependencyLoaded(index: number, dep: any): void {
if (index === 0) {
window.PDFObject = dep;
}
}
getEmbedScript(template: string, width: number, height: number): string{
//const configUri = this.data.config.uri || '';
//const script = String.format(template, this.getSerializedLocales(), configUri, this.helper.iiifResourceUri, this.helper.collectionIndex, this.helper.manifestIndex, this.helper.sequenceIndex, this.helper.canvasIndex, width, height, this.data.embedScriptUri);
const appUri: string = this.getAppUri();
const iframeSrc: string = `${appUri}#?manifest=${this.helper.manifestUri}&c=${this.helper.collectionIndex}&m=${this.helper.manifestIndex}&s=${this.helper.sequenceIndex}&cv=${this.helper.canvasIndex}`;
const script: string = Utils.Strings.format(template, iframeSrc, width.toString(), height.toString());
return script;
}
}