Skip to content

Commit c0a3395

Browse files
author
Christoph Haas
committed
Merged webodf#28 - ImageViewerPlugin.js
1 parent ef5f711 commit c0a3395

File tree

3 files changed

+177
-2
lines changed

3 files changed

+177
-2
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ add_custom_command(
213213
--js ${CMAKE_CURRENT_SOURCE_DIR}/ODFViewerPlugin.js
214214
--js ${CMAKE_CURRENT_BINARY_DIR}/PDFViewerPlugin.css.js
215215
--js ${CMAKE_CURRENT_SOURCE_DIR}/PDFViewerPlugin.js
216+
--js ${CMAKE_CURRENT_SOURCE_DIR}/ImageViewerPlugin.js
216217
--js ${CMAKE_CURRENT_BINARY_DIR}/viewerjsversion.js
217218
--js ${CMAKE_CURRENT_BINARY_DIR}/viewer.css.js
218219
--js ${CMAKE_CURRENT_BINARY_DIR}/viewerTouch.css.js
@@ -226,7 +227,8 @@ add_custom_command(
226227
ODFViewerPlugin.js
227228
PDFViewerPlugin.css.js-target
228229
PDFViewerPlugin.js
229-
${CMAKE_CURRENT_BINARY_DIR}/viewerjsversion.js
230+
ImageViewerPlugin.js
231+
${CMAKE_CURRENT_BINARY_DIR}/viewerjsversion.js
230232
viewer.css.js-target
231233
viewerTouch.css.js-target
232234
viewer.js

ImageViewerPlugin.js

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/**
2+
* Created in 31/01/2014 21:22:32
3+
* @author Daniele P. <daniele.pignedoli@gmail.com>
4+
*
5+
* @license http://www.gnu.org/licenses/gpl.html
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details:
15+
* http://www.gnu.org/licenses/gpl.html
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20+
* MA 02110-1301, USA
21+
* */
22+
23+
function ImageViewerPlugin() {
24+
"use strict";
25+
26+
var self = this;
27+
28+
this.initialize = function (viewerElement, documentUrl) {
29+
var img = new Image();
30+
img.onload = function () {
31+
self.setImage(img, viewerElement);
32+
};
33+
// @todo Handle the error when unable to load the image.
34+
img.src = documentUrl;
35+
};
36+
37+
function loadScript(path, callback) {
38+
var script = document.createElement('script');
39+
script.async = false;
40+
script.src = path;
41+
script.type = 'text/javascript';
42+
script.onload = callback || script.onload;
43+
document.getElementsByTagName('head')[0].appendChild(script);
44+
}
45+
46+
function scrollIntoView(elem) {}
47+
48+
function isScrolledIntoView(elem) {}
49+
50+
function getDomPage(page) {}
51+
52+
function getPageText(page) {}
53+
54+
this.setImage = function (image, container) {
55+
var domPage, image_container;
56+
domPage = document.createElement('div');
57+
domPage.id = 'pageContainer1';
58+
domPage.className = 'page';
59+
image_container = document.createElement('img');
60+
image_container.src = image.src;
61+
container.appendChild(domPage);
62+
image_container.width = domPage.clientWidth;
63+
self.image_container = image_container;
64+
self.original_width = image.width;
65+
self.original_height = domPage.clientHeight;
66+
domPage.appendChild(image_container);
67+
self.domPage = domPage;
68+
self.setZoomLevel(image_container.width / image.width);
69+
self.onLoad(image_container.width / image.width);
70+
};
71+
72+
73+
this.isSlideshow = function () {
74+
return false;
75+
};
76+
77+
this.onLoad = function (zoomlevel) {};
78+
79+
this.getWidth = function () {
80+
return self.image_container.width;
81+
};
82+
83+
this.getHeight = function () {
84+
return self.image_container.height;
85+
};
86+
87+
this.fitToWidth = function (width) {};
88+
89+
this.fitToHeight = function (height) {};
90+
91+
this.fitToPage = function (width, height) {};
92+
93+
this.fitSmart = function (width) {};
94+
95+
this.getZoomLevel = function () {
96+
return self.zoom;
97+
};
98+
99+
this.setZoomLevel = function (value) {
100+
self.zoom = value;
101+
self.image_container.width = self.original_width * value;
102+
if (self.image_container.width > self.domPage.clientWidth) {
103+
self.triggerScrollBars(true);
104+
} else {
105+
self.triggerScrollBars(false);
106+
}
107+
};
108+
109+
// Sometimes happen the scrollbars get under the toolbars, we must
110+
// find a way to prevent it, but playing with css in this way is not
111+
// the best solution.
112+
this.triggerScrollBars = function (enable) {
113+
/*
114+
if (true === enable) {
115+
document.getElementById('toolbarContainer').style.marginBottom = '10px';
116+
document.getElementById('toolbarContainer').style.width = (self.domPage.clientWidth - 20) + 'px';
117+
} else {
118+
document.getElementById('toolbarContainer').style.marginBottom = '0';
119+
document.getElementById('toolbarContainer').style.width = (self.domPage.clientWidth) + 'px';
120+
}
121+
*/
122+
};
123+
124+
this.onScroll = function () {
125+
// @todo Some kind of magnify tool would be great.
126+
return true;
127+
};
128+
129+
this.getPluginName = function () {
130+
return "ImageViewerPlugin.js"
131+
};
132+
133+
this.getPluginVersion = function () {
134+
return "From Source";
135+
};
136+
137+
this.getPageInView = function () {
138+
return 1;
139+
};
140+
141+
this.getPages = function () {
142+
return [];
143+
};
144+
145+
this.showPage = function (n) {};
146+
147+
this.getPluginURL = function () {
148+
return "https://github.com/kogmbh/ViewerJS/pull/28";
149+
};
150+
}

PluginLoader.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,30 @@
7171
},
7272
path: "./PDFViewerPlugin",
7373
getClass: function() { return PDFViewerPlugin; }
74-
}
74+
},
75+
(function() {
76+
var imageMimetypes = [
77+
'image/jpeg',
78+
'image/pjpeg',
79+
'image/gif',
80+
'image/png'];
81+
var imageFileExtensions = [
82+
'png',
83+
'jpg',
84+
'jpeg',
85+
'gif'];
86+
87+
return {
88+
supportsMimetype: function(mimetype) {
89+
return (imageMimetypes.indexOf(mimetype) !== -1);
90+
},
91+
supportsFileExtension: function(extension) {
92+
return (imageFileExtensions.indexOf(extension) !== -1);
93+
},
94+
path: "./ImageViewerPlugin",
95+
getClass: function() { return ImageViewerPlugin; }
96+
};
97+
}())
7598
];
7699

77100

0 commit comments

Comments
 (0)