|
1
|
|
|
/** |
|
2
|
|
|
* Copyright (C) 2012 KO GmbH <[email protected]> |
|
3
|
|
|
* Copyright (C) 2020-2022 grommunio GmbH <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @licstart |
|
6
|
|
|
* This file is part of ViewerJS. |
|
7
|
|
|
* |
|
8
|
|
|
* ViewerJS is free software: you can redistribute it and/or modify it |
|
9
|
|
|
* under the terms of the GNU Affero General Public License (GNU AGPL) |
|
10
|
|
|
* as published by the Free Software Foundation, either version 3 of |
|
11
|
|
|
* the License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* ViewerJS is distributed in the hope that it will be useful, but |
|
14
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
19
|
|
|
* along with ViewerJS. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* @licend |
|
21
|
|
|
* |
|
22
|
|
|
* @source: http://viewerjs.org/ |
|
23
|
|
|
* @source: http://github.com/kogmbh/ViewerJS |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
/*global runtime, document, odf, gui, console, webodf*/ |
|
27
|
|
|
|
|
28
|
|
|
function ODFViewerPlugin() { |
|
29
|
|
|
"use strict"; |
|
30
|
|
|
|
|
31
|
|
|
function init( callback ) { |
|
32
|
|
|
var lib = document.createElement('script'), |
|
33
|
|
|
pluginCSS; |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
lib.async = false; |
|
36
|
|
|
lib.src = './webodf.js'; |
|
37
|
|
|
lib.type = 'text/javascript'; |
|
38
|
|
|
lib.onload = function () { |
|
39
|
|
|
runtime.loadClass('gui.HyperlinkClickHandler'); |
|
40
|
|
|
runtime.loadClass('odf.OdfCanvas'); |
|
41
|
|
|
runtime.loadClass('ops.Session'); |
|
42
|
|
|
runtime.loadClass('gui.CaretManager'); |
|
43
|
|
|
runtime.loadClass("gui.HyperlinkTooltipView"); |
|
44
|
|
|
runtime.loadClass('gui.SessionController'); |
|
45
|
|
|
runtime.loadClass('gui.SvgSelectionView'); |
|
46
|
|
|
runtime.loadClass('gui.SelectionViewManager'); |
|
47
|
|
|
runtime.loadClass('gui.ShadowCursor'); |
|
48
|
|
|
runtime.loadClass('gui.SessionView'); |
|
49
|
|
|
|
|
50
|
|
|
callback(); |
|
51
|
|
|
}; |
|
52
|
|
|
|
|
53
|
|
|
document.head.appendChild(lib); |
|
54
|
|
|
|
|
55
|
|
|
// pluginCSS = /**@type{!HTMLStyleElement}*/(document.createElementNS(document.head.namespaceURI, 'style')); |
|
56
|
|
|
// pluginCSS.setAttribute('media', 'screen, print, handheld, projection'); |
|
57
|
|
|
// pluginCSS.setAttribute('type', 'text/css'); |
|
58
|
|
|
// pluginCSS.appendChild(document.createTextNode(ODFViewerPlugin_css)); |
|
59
|
|
|
// document.head.appendChild(pluginCSS); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// that should probably be provided by webodf |
|
63
|
|
|
function nsResolver( prefix ) { |
|
64
|
|
|
var ns = { |
|
65
|
|
|
'draw': "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0", |
|
66
|
|
|
'presentation': "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0", |
|
67
|
|
|
'text': "urn:oasis:names:tc:opendocument:xmlns:text:1.0", |
|
68
|
|
|
'office': "urn:oasis:names:tc:opendocument:xmlns:office:1.0" |
|
69
|
|
|
}; |
|
70
|
|
|
return ns[prefix] || console.log('prefix [' + prefix + '] unknown.'); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
var self = this, |
|
74
|
|
|
pluginName = "WebODF", |
|
75
|
|
|
pluginURL = "http://webodf.org", |
|
76
|
|
|
odfCanvas = null, |
|
77
|
|
|
odfElement = null, |
|
78
|
|
|
initialized = false, |
|
|
|
|
|
|
79
|
|
|
root = null, |
|
80
|
|
|
documentType = null, |
|
81
|
|
|
pages = [], |
|
|
|
|
|
|
82
|
|
|
currentPage = null; |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
this.initialize = function ( viewerElement, documentUrl ) { |
|
85
|
|
|
// If the URL has a fragment (#...), try to load the file it represents |
|
86
|
|
|
init(function () { |
|
87
|
|
|
var session, |
|
88
|
|
|
sessionController, |
|
89
|
|
|
sessionView, |
|
90
|
|
|
odtDocument, |
|
91
|
|
|
shadowCursor, |
|
92
|
|
|
selectionViewManager, |
|
93
|
|
|
caretManager, |
|
94
|
|
|
localMemberId = 'localuser', |
|
95
|
|
|
hyperlinkTooltipView, |
|
96
|
|
|
eventManager; |
|
97
|
|
|
|
|
98
|
|
|
odfElement = document.getElementById('canvas'); |
|
99
|
|
|
odfCanvas = new odf.OdfCanvas(odfElement); |
|
100
|
|
|
odfCanvas.load(documentUrl); |
|
101
|
|
|
|
|
102
|
|
|
odfCanvas.addListener('statereadychange', function () { |
|
103
|
|
|
root = odfCanvas.odfContainer().rootElement; |
|
104
|
|
|
initialized = true; |
|
|
|
|
|
|
105
|
|
|
documentType = odfCanvas.odfContainer().getDocumentType(root); |
|
106
|
|
|
if ( documentType === 'text' ) { |
|
107
|
|
|
odfCanvas.enableAnnotations(true, false); |
|
108
|
|
|
|
|
109
|
|
|
session = new ops.Session(odfCanvas); |
|
110
|
|
|
odtDocument = session.getOdtDocument(); |
|
111
|
|
|
shadowCursor = new gui.ShadowCursor(odtDocument); |
|
112
|
|
|
sessionController = new gui.SessionController(session, localMemberId, shadowCursor, {}); |
|
113
|
|
|
eventManager = sessionController.getEventManager(); |
|
114
|
|
|
caretManager = new gui.CaretManager(sessionController, odfCanvas.getViewport()); |
|
115
|
|
|
selectionViewManager = new gui.SelectionViewManager(gui.SvgSelectionView); |
|
116
|
|
|
sessionView = new gui.SessionView({ |
|
|
|
|
|
|
117
|
|
|
caretAvatarsInitiallyVisible: false |
|
118
|
|
|
}, localMemberId, session, sessionController.getSessionConstraints(), caretManager, selectionViewManager); |
|
119
|
|
|
selectionViewManager.registerCursor(shadowCursor); |
|
120
|
|
|
hyperlinkTooltipView = new gui.HyperlinkTooltipView(odfCanvas, |
|
121
|
|
|
sessionController.getHyperlinkClickHandler().getModifier); |
|
122
|
|
|
eventManager.subscribe("mousemove", hyperlinkTooltipView.showTooltip); |
|
123
|
|
|
eventManager.subscribe("mouseout", hyperlinkTooltipView.hideTooltip); |
|
124
|
|
|
|
|
125
|
|
|
var op = new ops.OpAddMember(); |
|
126
|
|
|
op.init({ |
|
127
|
|
|
memberid: localMemberId, |
|
128
|
|
|
setProperties: { |
|
129
|
|
|
fillName: runtime.tr("Unknown Author"), |
|
130
|
|
|
color: "blue" |
|
131
|
|
|
} |
|
132
|
|
|
}); |
|
133
|
|
|
session.enqueue([op]); |
|
134
|
|
|
sessionController.insertLocalCursor(); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
self.onLoad(); |
|
138
|
|
|
}); |
|
139
|
|
|
}); |
|
140
|
|
|
}; |
|
141
|
|
|
|
|
142
|
|
|
this.isSlideshow = function () { |
|
143
|
|
|
return documentType === 'presentation'; |
|
144
|
|
|
}; |
|
145
|
|
|
|
|
146
|
|
|
this.onLoad = function () { |
|
147
|
|
|
}; |
|
148
|
|
|
|
|
149
|
|
|
this.fitToWidth = function ( width ) { |
|
150
|
|
|
odfCanvas.fitToWidth(width); |
|
151
|
|
|
}; |
|
152
|
|
|
|
|
153
|
|
|
this.fitToHeight = function ( height ) { |
|
154
|
|
|
odfCanvas.fitToHeight(height); |
|
155
|
|
|
}; |
|
156
|
|
|
|
|
157
|
|
|
this.fitToPage = function ( width, height ) { |
|
158
|
|
|
odfCanvas.fitToContainingElement(width, height); |
|
159
|
|
|
}; |
|
160
|
|
|
|
|
161
|
|
|
this.fitSmart = function ( width ) { |
|
162
|
|
|
odfCanvas.fitSmart(width); |
|
163
|
|
|
}; |
|
164
|
|
|
|
|
165
|
|
|
this.getZoomLevel = function () { |
|
166
|
|
|
return odfCanvas.getZoomLevel(); |
|
167
|
|
|
}; |
|
168
|
|
|
|
|
169
|
|
|
this.setZoomLevel = function ( value ) { |
|
170
|
|
|
odfCanvas.setZoomLevel(value); |
|
171
|
|
|
}; |
|
172
|
|
|
|
|
173
|
|
|
// return a list of tuples (pagename, pagenode) |
|
174
|
|
|
this.getPages = function () { |
|
175
|
|
|
var pageNodes = Array.prototype.slice.call(root.getElementsByTagNameNS(nsResolver('draw'), 'page')), |
|
176
|
|
|
pages = [], |
|
177
|
|
|
i, |
|
178
|
|
|
tuple; |
|
179
|
|
|
|
|
180
|
|
|
for ( i = 0; i < pageNodes.length; i += 1 ) { |
|
181
|
|
|
tuple = [ |
|
182
|
|
|
pageNodes[i].getAttribute('draw:name'), |
|
183
|
|
|
pageNodes[i] |
|
184
|
|
|
]; |
|
185
|
|
|
pages.push(tuple); |
|
186
|
|
|
} |
|
187
|
|
|
return pages; |
|
188
|
|
|
}; |
|
189
|
|
|
|
|
190
|
|
|
this.showPage = function ( n ) { |
|
191
|
|
|
odfCanvas.showPage(n); |
|
192
|
|
|
}; |
|
193
|
|
|
|
|
194
|
|
|
this.getPluginName = function () { |
|
195
|
|
|
return pluginName; |
|
196
|
|
|
}; |
|
197
|
|
|
|
|
198
|
|
|
this.getPluginVersion = function () { |
|
199
|
|
|
var version; |
|
200
|
|
|
|
|
201
|
|
|
if ( String(typeof webodf) !== "undefined" ) { |
|
202
|
|
|
version = webodf.Version; |
|
203
|
|
|
} else { |
|
204
|
|
|
version = "Unknown"; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
return version; |
|
208
|
|
|
}; |
|
209
|
|
|
|
|
210
|
|
|
this.getPluginURL = function () { |
|
211
|
|
|
return pluginURL; |
|
212
|
|
|
}; |
|
213
|
|
|
} |
|
214
|
|
|
|