forked from h44z/ViewerJS
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathImageViewerPlugin.js
More file actions
executable file
·140 lines (110 loc) · 3.52 KB
/
ImageViewerPlugin.js
File metadata and controls
executable file
·140 lines (110 loc) · 3.52 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
function ImageViewerPlugin() {
"use strict";
var imgElement = undefined,
self = this,
rotation = 0,
currentPage = 1;
function initCSS() {
var pluginCSS;
pluginCSS = /**@type{!HTMLStyleElement}*/(document.createElementNS(document.head.namespaceURI, 'style'));
pluginCSS.setAttribute('media', 'screen, print, handheld, projection');
pluginCSS.setAttribute('type', 'text/css');
pluginCSS.appendChild(document.createTextNode(ImageViewerPlugin_css));
document.head.appendChild(pluginCSS);
}
function initButtons() {
var leftToolbar = document.getElementById('toolbarLeft');
// hide unused elements
document.getElementById("navButtons").style.display = 'none';
document.getElementById("pageNumberLabel").style.display = 'none';
document.getElementById("pageNumber").style.display = 'none';
document.getElementById("numPages").style.display = 'none';
leftToolbar.style.visibility = "visible";
var buttonSeperator = document.createElement("div");
buttonSeperator.setAttribute('class', 'splitToolbarButtonSeparator');
var rotateLeft = document.createElement("button");
rotateLeft.setAttribute('class', 'toolbarButton pageDown flipHorizontal');
rotateLeft.setAttribute('title', 'Rotate left');
var rotateRight = document.createElement("button");
rotateRight.setAttribute('class', 'toolbarButton pageDown');
rotateRight.setAttribute('title', 'Rotate right');
leftToolbar.appendChild(rotateLeft);
leftToolbar.appendChild(buttonSeperator);
leftToolbar.appendChild(rotateRight);
// Attach events to the above buttons
rotateLeft.addEventListener('click', function () {
imageRotateLeft();
});
rotateRight.addEventListener('click', function () {
imageRotateRight();
});
}
function imageRotateLeft() {
if(rotation <= 0) {
rotation = 360;
}
rotation -= 90;
document.getElementById("image").className = 'rotate' + rotation;
}
function imageRotateRight() {
if(rotation >= 360) {
rotation = 0;
}
rotation += 90;
document.getElementById("image").className = 'rotate' + rotation;
}
this.initialize = function (viewerElement, documentUrl) {
// If the URL has a fragment (#...), try to load the file it represents
imgElement=document.createElement("img");
imgElement.setAttribute('src', documentUrl);
imgElement.setAttribute('alt', 'na');
imgElement.setAttribute('id', 'image');
viewerElement.appendChild(imgElement);
viewerElement.style.overflow = "auto";
self.onLoad();
initCSS();
initButtons();
};
this.isSlideshow = function () {
return false;
};
this.onLoad = function () {};
this.fitToWidth = function (width) {
imgElement.width = width;
};
this.fitToHeight = function (height) {
imgElement.height = height;
};
this.fitToPage = function (width, height) {
imgElement.width = width;
};
this.fitSmart = function (width) {
imgElement.width = width;
};
this.getZoomLevel = function () {
return imgElement.width / imgElement.naturalWidth;
};
this.setZoomLevel = function (value) {
imgElement.width = value * imgElement.naturalWidth;
};
// return a list of tuples (pagename, pagenode)
this.getPages = function () {
return [1, 2];
};
this.showPage = function (n) {
if(n === currentPage) {
imgElement.parentNode.scrollTop -= 100;
} else {
imgElement.parentNode.scrollTop += 100;
}
};
this.getPluginName = function () {
return "ImageViewerPlugin";
};
this.getPluginVersion = function () {
return "From Source";
};
this.getPluginURL = function () {
return "https://github.com/in4mates/ViewerJS";
};
}