mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
103 lines
3.1 KiB
Plaintext
103 lines
3.1 KiB
Plaintext
<%= stylesheet_link_tag "editor" %>
|
||
|
||
<div class="form">
|
||
<div id="iframeEditor">
|
||
</div>
|
||
</div>
|
||
|
||
<script src="<%= Rails.configuration.urlApi %>"></script>
|
||
|
||
<script type="text/javascript" language="javascript">
|
||
|
||
var docEditor;
|
||
|
||
var innerAlert = function (message) {
|
||
if (console && console.log)
|
||
console.log(message);
|
||
};
|
||
|
||
var onAppReady = function () {
|
||
innerAlert("Document editor ready");
|
||
};
|
||
|
||
var onDocumentStateChange = function (event) {
|
||
var title = document.title.replace(/\*$/g, "");
|
||
document.title = title + (event.data ? "*" : "");
|
||
};
|
||
|
||
var onRequestEditRights = function () {
|
||
location.href = location.href.replace(RegExp("action=view?&", "i"), "");
|
||
};
|
||
|
||
var onError = function (event) {
|
||
if (event)
|
||
innerAlert(event.data);
|
||
};
|
||
|
||
var onOutdatedVersion = function (event) {
|
||
location.reload(true);
|
||
};
|
||
|
||
var replaceActionLink = function(href, linkParam) {
|
||
var link;
|
||
var actionIndex = href.indexOf("&actionLink=");
|
||
if (actionIndex != -1) {
|
||
var endIndex = href.indexOf("&", actionIndex + "&actionLink=".length);
|
||
if (endIndex != -1) {
|
||
link = href.substring(0, actionIndex) + href.substring(endIndex) + "&actionLink=" + encodeURIComponent(linkParam);
|
||
} else {
|
||
link = href.substring(0, actionIndex) + "&actionLink=" + encodeURIComponent(linkParam);
|
||
}
|
||
} else {
|
||
link = href + "&actionLink=" + encodeURIComponent(linkParam);
|
||
}
|
||
return link;
|
||
}
|
||
|
||
var onMakeActionLink = function (event) {
|
||
var actionData = event.data;
|
||
var linkParam = JSON.stringify(actionData);
|
||
docEditor.setActionLink(replaceActionLink(location.href, linkParam));
|
||
};
|
||
|
||
var сonnectEditor = function () {
|
||
|
||
var config = <%= raw @file.get_config.to_json %>;
|
||
|
||
config.width = "100%";
|
||
config.height = "100%";
|
||
config.events = {
|
||
'onAppReady': onAppReady,
|
||
'onDocumentStateChange': onDocumentStateChange,
|
||
'onError': onError,
|
||
'onOutdatedVersion': onOutdatedVersion,
|
||
'onMakeActionLink': onMakeActionLink,
|
||
};
|
||
|
||
<%
|
||
h = @file.get_history
|
||
if h %>
|
||
config.events['onRequestHistory'] = function () {
|
||
docEditor.refreshHistory(<%= raw h[:hist].to_json %>);
|
||
};
|
||
config.events['onRequestHistoryData'] = function (event) {
|
||
var ver = event.data;
|
||
var histData = <%= raw h[:histData].to_json %>;
|
||
docEditor.setHistoryData(histData[ver]);
|
||
};
|
||
config.events['onRequestHistoryClose'] = function () {
|
||
document.location.reload();
|
||
};
|
||
<% end
|
||
%>
|
||
|
||
docEditor = new DocsAPI.DocEditor("iframeEditor", config);
|
||
};
|
||
|
||
if (window.addEventListener) {
|
||
window.addEventListener("load", сonnectEditor);
|
||
} else if (window.attachEvent) {
|
||
window.attachEvent("load", сonnectEditor);
|
||
}
|
||
|
||
</script> |