Skip to content
This repository was archived by the owner on Oct 2, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ <h1 data-l10n-id="import"></h1>
<div role="main" class="header-only">
<div class="form">
<fieldset class="button-block">
<input type="file" multiple accept="text/html,text/plain,application/vnd.oasis.opendocument.text,.odt" id="uploadDialogFiles" data-enter="uploadFromDialog">
<input type="file" multiple id="uploadDialogFiles" data-enter="uploadFromDialog">
</fieldset>
</div>
</div>
Expand Down Expand Up @@ -334,6 +334,7 @@ <h1 id="fileName" class="no-zen"><span id="currentFileLocation" style="display:n
<ul role="tabs" id="editTabs">
<div role="tab" id="tab-design">
<iframe class="editor" id="editor" sandbox="allow-scripts" data-focus="hideToolbar" data-blur="showToolbar" src=""></iframe>
<iframe class="editor" id="viewerJS" src="" allowfullscreen></iframe>
<div role="toolbar" id="edit-bar">
<ul id="edit-zone">
<li><button class="sticky icon-bold" id="bold" data-click="formatDoc" data-click-action="bold"></button></li>
Expand Down
661 changes: 661 additions & 0 deletions modules/ViewerJS/AGPL-3.0.txt

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions modules/ViewerJS/ODFViewerPlugin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (C) 2013-2014 KO GmbH <[email protected]>
*
* @licstart
* This file is part of WebODF.
*
* WebODF 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.
*
* WebODF 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 WebODF. If not, see <http://www.gnu.org/licenses/>.
* @licend
*
* @source: http://www.webodf.org/
* @source: https://github.com/kogmbh/WebODF/
*/

@namespace cursor url(urn:webodf:names:cursor);

.caret {
opacity: 0 !important;
}
219 changes: 219 additions & 0 deletions modules/ViewerJS/ODFViewerPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/**
* Copyright (C) 2012 KO GmbH <[email protected]>
*
* @licstart
* This file is part of WebODF.
*
* WebODF 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.
*
* WebODF 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 WebODF. If not, see <http://www.gnu.org/licenses/>.
* @licend
*
* @source: http://www.webodf.org/
* @source: https://github.com/kogmbh/WebODF/
*/

/*global runtime, document, odf, gui, console, webodf*/

function ODFViewerPlugin() {
"use strict";

function init(callback) {
var lib = document.createElement('script'),
pluginCSS;

lib.async = false;
lib.src = './webodf.js';
lib.type = 'text/javascript';
lib.onload = function () {
runtime.loadClass('gui.HyperlinkClickHandler');
runtime.loadClass('odf.OdfCanvas');
runtime.loadClass('ops.Session');
runtime.loadClass('gui.CaretManager');
runtime.loadClass("gui.HyperlinkTooltipView");
runtime.loadClass('gui.SessionController');
runtime.loadClass('gui.SvgSelectionView');
runtime.loadClass('gui.SelectionViewManager');
runtime.loadClass('gui.ShadowCursor');
runtime.loadClass('gui.SessionView');

callback();
};

document.getElementsByTagName('head')[0].appendChild(lib);

pluginCSS = document.createElement('link');
pluginCSS.setAttribute("rel", "stylesheet");
pluginCSS.setAttribute("type", "text/css");
pluginCSS.setAttribute("href", "./ODFViewerPlugin.css");
document.head.appendChild(pluginCSS);
}

// 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,
pluginName = "WebODF",
pluginURL = "http://webodf.org",
odfCanvas = null,
odfElement = null,
initialized = false,
root = null,
documentType = null,
pages = [],
currentPage = null;

this.initialize = function (viewerElement, documentUrl) {
// If the URL has a fragment (#...), try to load the file it represents
init(function () {
var session,
sessionController,
sessionView,
odtDocument,
shadowCursor,
selectionViewManager,
caretManager,
localMemberId = 'localuser',
hyperlinkTooltipView,
eventManager;

odfElement = document.getElementById('canvas');
odfCanvas = new odf.OdfCanvas(odfElement);
odfCanvas.load(documentUrl);

odfCanvas.addListener('statereadychange', function () {
root = odfCanvas.odfContainer().rootElement;
initialized = true;
documentType = odfCanvas.odfContainer().getDocumentType(root);
if (documentType === 'text') {
odfCanvas.enableAnnotations(true, false);

session = new ops.Session(odfCanvas);
odtDocument = session.getOdtDocument();
shadowCursor = new gui.ShadowCursor(odtDocument);
sessionController = new gui.SessionController(session, localMemberId, shadowCursor, {});
eventManager = sessionController.getEventManager();
caretManager = new gui.CaretManager(sessionController, odfCanvas.getViewport());
selectionViewManager = new gui.SelectionViewManager(gui.SvgSelectionView);
sessionView = new gui.SessionView({
caretAvatarsInitiallyVisible: false
}, localMemberId, session, sessionController.getSessionConstraints(), caretManager, selectionViewManager);
selectionViewManager.registerCursor(shadowCursor);
hyperlinkTooltipView = new gui.HyperlinkTooltipView(odfCanvas,
sessionController.getHyperlinkClickHandler().getModifier);
eventManager.subscribe("mousemove", hyperlinkTooltipView.showTooltip);
eventManager.subscribe("mouseout", hyperlinkTooltipView.hideTooltip);

var op = new ops.OpAddMember();
op.init({
memberid: localMemberId,
setProperties: {
fillName: runtime.tr("Unknown Author"),
color: "blue"
}
});
session.enqueue([op]);
sessionController.insertLocalCursor();
}

self.onLoad();
});
});
};

this.isSlideshow = function () {
return documentType === 'presentation';
};

this.onLoad = function () {};

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);
};

this.getZoomLevel = function () {
return odfCanvas.getZoomLevel();
};

this.setZoomLevel = function (value) {
odfCanvas.setZoomLevel(value);
};

// return a list of tuples (pagename, pagenode)
this.getPages = function () {
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;
};

this.showPage = function (n) {
odfCanvas.showPage(n);
};

this.getPluginName = function () {
return pluginName;
};

this.getPluginVersion = function () {
var version;

if (String(typeof webodf) !== "undefined") {
version = webodf.Version;
} else {
version = "Unknown";
}

return version;
};

this.getPluginURL = function () {
return pluginURL;
};
}
36 changes: 36 additions & 0 deletions modules/ViewerJS/PDFViewerPlugin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.page {
margin: 7px auto 7px auto;
position: relative;
overflow: hidden;
background-clip: content-box;
background-color: white;

box-shadow: 0px 0px 7px rgba(0, 0, 0, 0.75);
-webkit-box-shadow: 0px 0px 7px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 7px rgba(0, 0, 0, 0.75);
-ms-box-shadow: 0px 0px 7px rgba(0, 0, 0, 0.75);
-o-box-shadow: 0px 0px 7px rgba(0, 0, 0, 0.75);
}

.textLayer {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
color: #000;
font-family: sans-serif;
overflow: hidden;
}

.textLayer > div {
color: transparent;
position: absolute;
line-height: 1;
white-space: pre;
cursor: text;
}

::selection { background:rgba(0,0,255,0.3); }
::-moz-selection { background:rgba(0,0,255,0.3); }

Loading