Import OnlyOffice code from the 'onlyoffice' branch and sframe it
This commit is contained in:
38
www/onlyoffice/document/app-oo.less
Normal file
38
www/onlyoffice/document/app-oo.less
Normal file
@@ -0,0 +1,38 @@
|
||||
@import (once) "../../customize/src/less2/include/browser.less";
|
||||
@import (once) "../../customize/src/less2/include/toolbar.less";
|
||||
@import (once) "../../customize/src/less2/include/markdown.less";
|
||||
@import (once) '../../customize/src/less2/include/fileupload.less';
|
||||
@import (once) '../../customize/src/less2/include/alertify.less';
|
||||
@import (once) '../../customize/src/less2/include/avatar.less';
|
||||
|
||||
.toolbar_main();
|
||||
.fileupload_main();
|
||||
.alertify_main();
|
||||
|
||||
// body
|
||||
&.cp-app-oo {
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
|
||||
#cp-toolbar {
|
||||
display: flex; // We need this to remove a 3px border at the bottom of the toolbar
|
||||
}
|
||||
|
||||
.cp-cryptpad-toolbar {
|
||||
padding: 0px;
|
||||
display: inline-block;
|
||||
}
|
||||
#cp-app-oo-container {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
background-color: lightgrey;
|
||||
display: flex;
|
||||
}
|
||||
#ooframe {
|
||||
flex: 1;
|
||||
border:none;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
}
|
||||
|
||||
23
www/onlyoffice/document/doc.js
Normal file
23
www/onlyoffice/document/doc.js
Normal file
@@ -0,0 +1,23 @@
|
||||
config = {
|
||||
"document": {
|
||||
"fileType": "docx",
|
||||
"key": "Khirz6zTPdfd7",
|
||||
"title": "test.docx",
|
||||
"url": "/onlyoffice/test.docx"
|
||||
},
|
||||
"documentType": "text",
|
||||
"editorConfig": {
|
||||
"user": {
|
||||
"id": "c0c3bf82-20d7-4663-bf6d-7fa39c598b1d",
|
||||
"name": "John Smith"
|
||||
}
|
||||
},
|
||||
"events": {
|
||||
"onDocumentStateChange": function(evt) { console.log("in change"); window.top.APP.onLocal(); },
|
||||
"onReady": function(evt) { console.log("in onReady"); window.top.onOOReady(); }
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var docEditor = new DocsAPI.DocEditor("placeholder", config);
|
||||
|
||||
14
www/onlyoffice/document/document.html
Normal file
14
www/onlyoffice/document/document.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="placeholder"></div>
|
||||
<script type="text/javascript" src="/onlyoffice/web-apps/apps/api/documents/api.js"></script>
|
||||
<script type="text/javascript" src="/onlyoffice/document/doc.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
38
www/onlyoffice/document/index.html
Normal file
38
www/onlyoffice/document/index.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>CryptPad</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="referrer" content="no-referrer" />
|
||||
<script async data-bootload="main.js" data-main="/common/boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
#sbox-iframe {
|
||||
position:fixed;
|
||||
top:0px;
|
||||
left:0px;
|
||||
bottom:0px;
|
||||
right:0px;
|
||||
width:100%;
|
||||
height:100%;
|
||||
border:none;
|
||||
margin:0;
|
||||
padding:0;
|
||||
overflow:hidden;
|
||||
}
|
||||
#sbox-filePicker-iframe {
|
||||
position: fixed;
|
||||
top:0; left:0;
|
||||
bottom:0; right:0;
|
||||
width:100%;
|
||||
height: 100%;
|
||||
border: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<iframe id="sbox-iframe">
|
||||
17
www/onlyoffice/document/inner.html
Normal file
17
www/onlyoffice/document/inner.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html class="cp-app-noscroll">
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||
<script async data-bootload="/onlyoffice/document/inner.js" data-main="/common/sframe-boot.js?ver=1.4" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
||||
<style>
|
||||
.loading-hidden { display: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="cp-app-oo">
|
||||
<div id="cp-toolbar" class="cp-toolbar-container"></div>
|
||||
<div id="cp-app-oo-container">
|
||||
<iframe id="ooframe" src="document.html" width="100%" height="100%">
|
||||
</iframe>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
308
www/onlyoffice/document/inner.js
Normal file
308
www/onlyoffice/document/inner.js
Normal file
@@ -0,0 +1,308 @@
|
||||
define([
|
||||
'jquery',
|
||||
'/common/toolbar3.js',
|
||||
'json.sortify',
|
||||
'/bower_components/nthen/index.js',
|
||||
'/common/sframe-common.js',
|
||||
'/common/common-interface.js',
|
||||
'/api/config',
|
||||
'/customize/messages.js',
|
||||
'/customize/application_config.js',
|
||||
'/bower_components/chainpad/chainpad.dist.js',
|
||||
|
||||
'/bower_components/file-saver/FileSaver.min.js',
|
||||
|
||||
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
|
||||
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
||||
'less!/customize/src/less2/main.less',
|
||||
], function (
|
||||
$,
|
||||
Toolbar,
|
||||
JSONSortify,
|
||||
nThen,
|
||||
SFCommon,
|
||||
UI,
|
||||
ApiConfig,
|
||||
Messages,
|
||||
AppConfig,
|
||||
ChainPad)
|
||||
{
|
||||
var saveAs = window.saveAs;
|
||||
|
||||
var ooReady = window.frames[0] && window.frames[0].frames[0] && window.frames[0].frames[0].editor;
|
||||
window.onOOReady = function () {
|
||||
ooReady = true;
|
||||
};
|
||||
|
||||
var APP = window.APP = {
|
||||
$: $
|
||||
};
|
||||
|
||||
var stringify = function (obj) {
|
||||
return JSONSortify(obj);
|
||||
};
|
||||
|
||||
var toolbar;
|
||||
|
||||
var andThen = function (common) {
|
||||
var config = {};
|
||||
|
||||
var emitResize = APP.emitResize = function () {
|
||||
var cw = $('#ooframe')[0].contentWindow;
|
||||
|
||||
var evt = cw.document.createEvent('UIEvents');
|
||||
evt.initUIEvent('resize', true, false, cw, 0);
|
||||
cw.dispatchEvent(evt);
|
||||
};
|
||||
|
||||
var saveToServer = APP.saveToServer = function () {
|
||||
config.onLocal();
|
||||
}
|
||||
|
||||
var callRemote = APP.callRemote = function() {
|
||||
config.onRemote();
|
||||
}
|
||||
|
||||
var saveDocument = APP.saveDocument = function () {
|
||||
var defaultName = "text.oot";
|
||||
UI.prompt(Messages.exportPrompt, defaultName, function (filename) {
|
||||
if (!(typeof(filename) === 'string' && filename)) { return; }
|
||||
console.log("In saveDocument");
|
||||
var content = window.frames[0].frames[0].editor.asc_nativeGetFile();
|
||||
var blob = new Blob([content], {type: "text/plain;charset=utf-8"});
|
||||
saveAs(blob, filename);
|
||||
});
|
||||
};
|
||||
|
||||
var loadDocument = APP.loadDocument = function (content, file) {
|
||||
console.log("Read " + content);
|
||||
return;
|
||||
window.frames[0].frames[0].editor.asc_CloseFile();
|
||||
var openResult = {bSerFormat: true, data: content, url: "http://localhost:3000/onlyoffice/", changes: null};
|
||||
window.frames[0].frames[0].editor.openDocument(openResult);
|
||||
};
|
||||
|
||||
var readOnly = false;
|
||||
var initializing = true;
|
||||
var $bar = $('#cp-toolbar');
|
||||
var Title;
|
||||
var cpNfInner;
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
|
||||
config = {
|
||||
readOnly: readOnly,
|
||||
patchTransformer: ChainPad.NaiveJSONTransformer,
|
||||
// cryptpad debug logging (default is 1)
|
||||
// logLevel: 0,
|
||||
validateContent: function (content) {
|
||||
try {
|
||||
JSON.parse(content);
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.log("Failed to parse, rejecting patch");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var setEditable = function (state) {
|
||||
console.log(state);
|
||||
};
|
||||
|
||||
var stringifyInner = function (textValue) {
|
||||
var obj = {
|
||||
content: textValue,
|
||||
metadata: metadataMgr.getMetadataLazy()
|
||||
};
|
||||
// stringify the json and send it into chainpad
|
||||
return stringify(obj);
|
||||
};
|
||||
|
||||
APP.onLocal = config.onLocal = function () {
|
||||
console.log(initializing, readOnly);
|
||||
if (initializing) { return; }
|
||||
if (readOnly) { return; }
|
||||
|
||||
if (!window.frames[0].frames[0] || !window.frames[0].frames[0].editor) {
|
||||
console.log("Cannot access editor");
|
||||
return;
|
||||
}
|
||||
console.log('ok');
|
||||
var data = window.frames[0].frames[0].editor.asc_nativeGetFile();
|
||||
var content = stringifyInner(data);
|
||||
APP.realtime.contentUpdate(content);
|
||||
};
|
||||
|
||||
config.onInit = function (info) {
|
||||
readOnly = metadataMgr.getPrivateData().readOnly;
|
||||
|
||||
Title = common.createTitle({});
|
||||
|
||||
var configTb = {
|
||||
displayed: [
|
||||
'userlist',
|
||||
'title',
|
||||
'useradmin',
|
||||
'spinner',
|
||||
'newpad',
|
||||
'share',
|
||||
'limit',
|
||||
'unpinnedWarning'
|
||||
],
|
||||
title: Title.getTitleConfig(),
|
||||
metadataMgr: metadataMgr,
|
||||
readOnly: readOnly,
|
||||
realtime: info.realtime,
|
||||
sfCommon: common,
|
||||
$container: $bar,
|
||||
$contentContainer: $('#cp-app-oo-container')
|
||||
};
|
||||
toolbar = APP.toolbar = Toolbar.create(configTb);
|
||||
Title.setToolbar(toolbar);
|
||||
|
||||
var $rightside = toolbar.$rightside;
|
||||
|
||||
|
||||
/* add an export button */
|
||||
var $export = common.createButton('export', true, {}, saveDocument);
|
||||
$rightside.append($export);
|
||||
var $import = common.createButton('import', true, {}, loadDocument);
|
||||
$rightside.append($import);
|
||||
var $save = common.createButton('save', true, {}, saveToServer);
|
||||
$save.click(function () {
|
||||
saveToServer();
|
||||
});
|
||||
$rightside.append($save);
|
||||
var $remote = common.createButton('remote', true, {}, callRemote);
|
||||
$remote.click(function () {
|
||||
callRemote();
|
||||
});
|
||||
$rightside.append($remote);
|
||||
|
||||
if (common.isLoggedIn()) {
|
||||
common.createButton('hashtag', true).appendTo($rightside);
|
||||
}
|
||||
|
||||
var $forget = common.createButton('forget', true, {}, function (err) {
|
||||
if (err) { return; }
|
||||
setEditable(false);
|
||||
});
|
||||
$rightside.append($forget);
|
||||
};
|
||||
|
||||
config.onReady = function (info) {
|
||||
if (APP.realtime !== info.realtime) {
|
||||
APP.realtime = info.realtime;
|
||||
}
|
||||
|
||||
if (!window.frames[0].frames[0] || !window.frames[0].frames[0].editor) {
|
||||
console.log("Cannot access editor");
|
||||
return;
|
||||
}
|
||||
|
||||
var userDoc = APP.realtime.getUserDoc();
|
||||
var isNew = false;
|
||||
var newDoc = '';
|
||||
if (userDoc === "" || userDoc === "{}") { isNew = true; }
|
||||
|
||||
if (userDoc !== "") {
|
||||
var hjson = JSON.parse(userDoc);
|
||||
|
||||
if (hjson && hjson.metadata) {
|
||||
metadataMgr.updateMetadata(hjson.metadata);
|
||||
}
|
||||
if (typeof (hjson) !== 'object' || Array.isArray(hjson) ||
|
||||
(hjson.metadata && typeof(hjson.metadata.type) !== 'undefined' &&
|
||||
hjson.metadata.type !== 'oo')) {
|
||||
var errorText = Messages.typeError;
|
||||
UI.errorLoadingScreen(errorText);
|
||||
throw new Error(errorText);
|
||||
}
|
||||
newDoc = hjson.content;
|
||||
} else {
|
||||
Title.updateTitle(Title.defaultTitle);
|
||||
}
|
||||
|
||||
loadDocument(newDoc);
|
||||
initializing = false;
|
||||
setEditable(!readOnly);
|
||||
UI.removeLoadingScreen();
|
||||
};
|
||||
|
||||
config.onRemote = function () {
|
||||
if (initializing) { return; }
|
||||
if (!window.frames[0].frames[0] || !window.frames[0].frames[0].editor) {
|
||||
console.log("Cannot access editor");
|
||||
return;
|
||||
}
|
||||
|
||||
// force readonly to prevent interlacing
|
||||
readOnly = true;
|
||||
|
||||
var previousData = window.frames[0].frames[0].editor.asc_nativeGetFile();
|
||||
var userDoc = APP.realtime.getUserDoc();
|
||||
|
||||
var json = JSON.parse(userDoc);
|
||||
if (json.metadata) {
|
||||
metadataMgr.updateMetadata(json.metadata);
|
||||
}
|
||||
var remoteDoc = json.content;
|
||||
if (remoteDoc!=previousData) {
|
||||
console.log("Remote content is different")
|
||||
console.log("Remote content hjson: " + remoteDoc);
|
||||
loadDocument(remoteDoc);
|
||||
common.notify();
|
||||
} else {
|
||||
console.log("Data is unchanged");
|
||||
}
|
||||
|
||||
readOnly = false;
|
||||
};
|
||||
|
||||
config.onAbort = function () {
|
||||
// inform of network disconnect
|
||||
setEditable(false);
|
||||
toolbar.failed();
|
||||
UI.alert(Messages.common_connectionLost, undefined, true);
|
||||
};
|
||||
|
||||
config.onConnectionChange = function (info) {
|
||||
setEditable(info.state);
|
||||
if (info.state) {
|
||||
initializing = true;
|
||||
UI.findOKButton().click();
|
||||
} else {
|
||||
UI.alert(Messages.common_connectionLost, undefined, true);
|
||||
}
|
||||
};
|
||||
|
||||
cpNfInner = common.startRealtime(config);
|
||||
|
||||
cpNfInner.onInfiniteSpinner(function () {
|
||||
setEditable(false);
|
||||
UI.confirm(Messages.realtime_unrecoverableError, function (yes) {
|
||||
if (!yes) { return; }
|
||||
common.gotoURL();
|
||||
});
|
||||
});
|
||||
|
||||
common.onLogout(function () { setEditable(false); });
|
||||
};
|
||||
|
||||
var main = function () {
|
||||
var common;
|
||||
|
||||
nThen(function (waitFor) {
|
||||
if (!ooReady) {
|
||||
window.onOOReady = waitFor();
|
||||
}
|
||||
$(waitFor(function () {
|
||||
UI.addLoadingScreen();
|
||||
}));
|
||||
SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
andThen(common);
|
||||
});
|
||||
};
|
||||
main();
|
||||
});
|
||||
43
www/onlyoffice/document/main.js
Normal file
43
www/onlyoffice/document/main.js
Normal file
@@ -0,0 +1,43 @@
|
||||
// Load #1, load as little as possible because we are in a race to get the loading screen up.
|
||||
define([
|
||||
'/bower_components/nthen/index.js',
|
||||
'/api/config',
|
||||
'/common/dom-ready.js',
|
||||
'/common/requireconfig.js',
|
||||
'/common/sframe-common-outer.js'
|
||||
], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) {
|
||||
var requireConfig = RequireConfig();
|
||||
|
||||
// Loaded in load #2
|
||||
nThen(function (waitFor) {
|
||||
DomReady.onReady(waitFor());
|
||||
}).nThen(function (waitFor) {
|
||||
var req = {
|
||||
cfg: requireConfig,
|
||||
req: [ '/common/loading.js' ],
|
||||
pfx: window.location.origin
|
||||
};
|
||||
window.rc = requireConfig;
|
||||
window.apiconf = ApiConfig;
|
||||
document.getElementById('sbox-iframe').setAttribute('src',
|
||||
ApiConfig.httpSafeOrigin + '/onlyoffice/document/inner.html?' + requireConfig.urlArgs +
|
||||
'#' + encodeURIComponent(JSON.stringify(req)));
|
||||
|
||||
// This is a cheap trick to avoid loading sframe-channel in parallel with the
|
||||
// loading screen setup.
|
||||
var done = waitFor();
|
||||
var onMsg = function (msg) {
|
||||
var data = JSON.parse(msg.data);
|
||||
if (data.q !== 'READY') { return; }
|
||||
window.removeEventListener('message', onMsg);
|
||||
var _done = done;
|
||||
done = function () { };
|
||||
_done();
|
||||
};
|
||||
window.addEventListener('message', onMsg);
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
SFCommonO.start({
|
||||
type: 'oo'
|
||||
});
|
||||
});
|
||||
});
|
||||
1
www/onlyoffice/document/test.bin
Normal file
1
www/onlyoffice/document/test.bin
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user