/** * @license * Copyright (C) 2014 KO GmbH * * @licstart * The JavaScript code in this page is free software: you can redistribute it * and/or modify it under the terms of the GNU Affero General Public License * (GNU AGPL) as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * The code is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this code. If not, see . * * @licend * @source: http://www.webodf.org/ * @source: https://github.com/kogmbh/WebODF/ */ // This code was created by pieces of Viewer.JS and can surely be reduced some more. // Idea is to not use Viewer.JS here, but to have custom code, for these reasons: // * the features of WebODF library should be shown, not Viewer.JS // * should also show as side-effect that custom UI is simple to do // * have another way the WebODF API is used function ODFViewer(url) { "use strict"; // that should probably be provided by webodf function nsResolver(prefix) { var ns = { 'draw' : "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0", 'presentation' : "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0", 'text' : "urn:oasis:names:tc:opendocument:xmlns:text:1.0", 'office' : "urn:oasis:names:tc:opendocument:xmlns:office:1.0" }; return ns[prefix] || console.log('prefix [' + prefix + '] unknown.'); } var self = this, odfCanvas = null, odfElement = null, root = null, documentType = null, kScrollbarPadding = 40, kDefaultScale = 'auto', initialized = false, isSlideshow = false, viewerElement = document.getElementById('viewer'), canvasContainer = document.getElementById('canvasContainer'), overlayNavigator = document.getElementById('overlayNavigator'), pageSwitcher = document.getElementById('toolbarLeft'), scaleSelector = document.getElementById('scaleSelect'), toolbarRight = document.getElementById('toolbarRight'), pages = [], currentPage = null, touchTimer; this.isPresentation = function () { return documentType === 'presentation'; }; this.getWidth = function () { return odfElement.clientWidth; }; this.getHeight = function () { return odfElement.clientHeight; }; this.fitToWidth = function (width) { odfCanvas.fitToWidth(width); }; this.fitToHeight = function (height) { odfCanvas.fitToHeight(height); }; this.fitToPage = function (width, height) { odfCanvas.fitToContainingElement(width, height); }; this.fitSmart = function (width) { odfCanvas.fitSmart(width); }; // return a list of tuples (pagename, pagenode) function getPages() { var pageNodes = Array.prototype.slice.call(root.getElementsByTagNameNS(nsResolver('draw'), 'page')), pages = [], i, tuple; for (i = 0; i < pageNodes.length; i += 1) { tuple = [ pageNodes[i].getAttribute('draw:name'), pageNodes[i] ]; pages.push(tuple); } return pages; }; function selectScaleOption(value) { // Retrieve the options from the zoom level