-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
123 lines (95 loc) · 2.38 KB
/
functions.js
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
// ---------- PAGE CONTROL ----------
function getPageNum() {
return PDFViewerApplication.page - 1;
}
function setPageNum(pagenum) {
PDFViewerApplication.page = pagenum + 1;
return;
}
function numPages() {
return PDFViewerApplication.pagesCount;
}
function goToNextPage() {
app.page = Math.min(app.page + 1, app.pagesCount);
return;
}
function goToPreviousPage() {
app.page = Math.max(app.page - 1, 1);
return;
}
// ---------- SIDEBAR CONTROL ----------
function getSidebarState() {
return PDFViewerApplication.pdfSidebar.isOpen;
}
function toggleSidebarState() {
PDFViewerApplication.pdfSidebar.toggle();
return;
}
function setSidebarState(newstate) {
if (newstate) {
PDFViewerApplication.pdfSidebar.open();
}
else {
PDFViewerApplication.pdfSidebar.close();
}
return;
}
function showSidebar() {
setSidebarState(true);
return;
}
function hideSidebar() {
setSidebarState(false);
return;
}
function resetSidebar() {
PDFViewerApplication.pdfSidebar.reset();
return;
}
// ---------- ZOOM CONTROL ----------
function resetZoom() {
PDFViewerApplication.zoomReset();
return;
}
function setZoomFactor(factor) {
PDFViewerApplication.pdfViewer.currentScaleValue = factor;
return;
}
function getZoomFactor(factor) {
return PDFViewerApplication.pdfViewer.currentScaleValue;
}
function getPageDimensions() {
var viewer = PDFViewerApplication.pdfViewer.viewer;
return [viewer.clientWidth, viewer.clientHeight]
}
// ---------- MISC ----------
function getCurrentFileUri() {
return PDFViewerApplication.url;
}
function hideFileOpener() {
PDFViewerApplication.appConfig.toolbar.openFile.setAttribute("hidden", "true");
return;
}
function openFind() {
PDFViewerApplication.findBar.open();
PDFViewerApplication.findBar.findField.focus();
return;
}
// ---------- EXECUTE ON LOAD ----------
function onRender() {
resetSidebar();
hideSidebar();
hideFileOpener();
resetZoom();
return;
}
function loadFile(fileuri) {
PDFViewerApplication.open(fileuri).then(onRender);
return;
}
// this runs as script (i.e. on file execution)
PDFViewerApplication.pdfViewer.eventBus.on("pagerendered", onRender);
PDFViewerApplication.pdfViewer.eventBus.on("pagesloaded", function() {setPageNum(0);});
// document.onkeydown = function (e) {
// return false;
// }