|
| 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 | +} |
0 commit comments