DocumentServer/OnlineEditorsExample/OnlineEditorsExampleNodeJS/views/editor.ejs
2015-04-29 19:10:50 +03:00

155 lines
5.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width" />
<title>ONLYOFFICE™</title>
<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="stylesheets/editor.css" />
</head>
<body>
<div class="form">
<div id="iframeEditor">
</div>
</div>
<script type="text/javascript" src="<%= apiUrl %>"></script>
<script type="text/javascript" language="javascript">
var docEditor;
var fileName = "<%= file.name %>";
var fileType = "<%= file.ext %>";
var innerAlert = function (message) {
if (console && console.log)
console.log(message);
};
var onReady = function () {
innerAlert("Document editor ready");
};
var onBack = function () {
location.href = "/index";
};
var onDocumentStateChange = function (event) {
var title = document.title.replace(/\*$/g, "");
document.title = title + (event.data ? "*" : "");
};
var onRequestEditRights = function () {
if (typeof DocsAPI.DocEditor.version == "function") {
var version = DocsAPI.DocEditor.version();
if ((parseFloat(version) || 0) >= 3) {
location.href = location.href.replace(RegExp("action=view\&?", "i"), "");
return;
}
}
docEditor.applyEditRights(true);
};
var onDocumentSave = function (event) {
SaveFileRequest(fileName, fileType, event.data);
};
var onError = function (event) {
if (console && console.log && event)
console.log(event.data);
};
var сonnectEditor = function () {
docEditor = new DocsAPI.DocEditor("iframeEditor",
{
width: "100%",
height: "100%",
type: "<%= editor.type %>",
documentType: "<%= editor.documentType %>",
document: {
title: fileName,
url: "<%= file.uri %>",
fileType: fileType,
key: "<%= editor.key %>",
vkey: "<%= editor.vKey %>",
info: {
author: "Me",
created: new Date().toDateString()
},
permissions: {
edit: "<%= editor.isEdit %>" == "true",
download: true
}
},
editorConfig: {
mode: "<%= editor.mode %>",
lang: "en",
callbackUrl: "<%- editor.callbackUrl %>",
embedded: {
saveUrl: "<%= file.uri %>",
embedUrl: "<%= file.uri %>",
shareUrl: "<%= file.uri %>",
toolbarDocked: "top"
}
},
events: {
"onReady": onReady,
"onBack": "<%= editor.canBackToFolder %>" == "true" ? onBack : undefined,
"onDocumentStateChange": onDocumentStateChange,
'onRequestEditRights': onRequestEditRights,
"onSave": onDocumentSave,
"onError": onError
}
});
};
if (window.addEventListener) {
window.addEventListener("load", сonnectEditor);
} else if (window.attachEvent) {
window.attachEvent("load", сonnectEditor);
}
function getXmlHttp() {
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (ex) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function SaveFileRequest(fileName, fileType, fileUri) {
var req = getXmlHttp();
if (console && console.log) {
req.onreadystatechange = function () {
if (req.readyState == 4) {
console.log(req.statusText);
if (req.status == 200) {
console.log(req.responseText);
}
}
};
}
var requestAddress = "save?"
+ "&filename=" + encodeURIComponent(fileName)
+ "&filetype=" + encodeURIComponent(fileType)
+ "&fileuri=" + encodeURIComponent(fileUri);
req.open("get", requestAddress, true);
req.send(fileUri);
}
</script>
</body>
</html>