diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..26cd12ac --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,11 @@ +{ + "extends": "@ownclouders", + "rules": { + "array-bracket-newline": ["error", "consistent"], + "multiline-ternary": ["error", "always-multiline"], + "no-var": "error", + "prefer-const": "error", + "object-shorthand": ["error", "always"], + "eqeqeq": ["error", "smart"] + } +} \ No newline at end of file diff --git a/.github/workflows/artifact.yml b/.github/workflows/artifact.yml index ad9c6a3a..9a8c85a3 100644 --- a/.github/workflows/artifact.yml +++ b/.github/workflows/artifact.yml @@ -2,6 +2,8 @@ name: Artifact on: workflow_dispatch: + push: + branches: [master] pull_request: types: [opened, reopened] branches: [master] diff --git a/.stylelintrc.json b/.stylelintrc.json new file mode 100644 index 00000000..2930c706 --- /dev/null +++ b/.stylelintrc.json @@ -0,0 +1,13 @@ +{ + "extends": ["stylelint-config-standard", "stylelint-config-sass-guidelines"], + "rules": { + "scss/at-extend-no-missing-placeholder": null, + "max-nesting-depth": null, + "selector-class-pattern": null, + "selector-max-compound-selectors": null, + "selector-max-id": null, + "selector-no-qualifying-type": null, + "property-no-vendor-prefix": null, + "string-quotes": "double" + } + } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 614b9c87..7a9187d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## 9.5.1 +## Added +- default empty templates +- support tiff format for inserting +- Finnish, Hebrew, Norwegian, Slovenian empty file templates + +## Changed +- demo server address changed +- editing pdf by default + ## 9.3.1 ## Changed - creating and editing pdf form diff --git a/appinfo/info.xml b/appinfo/info.xml index e02cafe8..245e3f7e 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -6,7 +6,7 @@ ONLYOFFICE connector allows you to view, edit and collaborate on text documents, spreadsheets and presentations within ownCloud using ONLYOFFICE Docs. This will create a new Edit in ONLYOFFICE action within the document library for Office documents. This allows multiple users to co-author documents in real time from the familiar web interface and save the changes back to your file storage. apl2 Ascensio System SIA - 9.3.1 + 9.5.1 Onlyoffice diff --git a/assets/document-formats b/assets/document-formats index 2b592018..8c1941e3 160000 --- a/assets/document-formats +++ b/assets/document-formats @@ -1 +1 @@ -Subproject commit 2b592018adbf03d9d6a9f1ab69b1e9d8af73e22c +Subproject commit 8c1941e3b896831b50a9956fefb36d6f78eb2e50 diff --git a/assets/document-templates b/assets/document-templates index dc3f298d..26da8649 160000 --- a/assets/document-templates +++ b/assets/document-templates @@ -1 +1 @@ -Subproject commit dc3f298ddb8932e385cf81563dd4d2c9429d59e2 +Subproject commit 26da864937e48e80ee667e3545e386405c16c10f diff --git a/controller/callbackcontroller.php b/controller/callbackcontroller.php index 07c4f86f..d3fd3651 100644 --- a/controller/callbackcontroller.php +++ b/controller/callbackcontroller.php @@ -363,7 +363,7 @@ public function emptyfile($doc) { } } - $templatePath = TemplateManager::getEmptyTemplatePath("en", ".docx"); + $templatePath = TemplateManager::getEmptyTemplatePath("default", ".docx"); $template = file_get_contents($templatePath); if (!$template) { diff --git a/controller/editorapicontroller.php b/controller/editorapicontroller.php index fbe2852a..3f91a0d3 100644 --- a/controller/editorapicontroller.php +++ b/controller/editorapicontroller.php @@ -234,7 +234,6 @@ public function fillempty($fileId) { * @param bool $desktop - desktop label * @param bool $template - file is template * @param string $anchor - anchor link - * @param bool $forceEdit - open editing * * @return JSONResponse * @@ -242,7 +241,7 @@ public function fillempty($fileId) { * @PublicPage * @CORS */ - public function config($fileId, $filePath = null, $shareToken = null, $version = 0, $inframe = false, $desktop = false, $template = false, $anchor = null, $forceEdit = false) { + public function config($fileId, $filePath = null, $shareToken = null, $version = 0, $inframe = false, $desktop = false, $template = false, $anchor = null) { $user = $this->userSession->getUser(); $userId = null; $accountId = null; @@ -381,7 +380,7 @@ public function config($fileId, $filePath = null, $shareToken = null, $version = && $file->isUpdateable() && !$isPersistentLock && (empty($shareToken) || ($share->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE); - $params["document"]["permissions"]["edit"] = $editable && ($forceEdit || !$canFillForms); + $params["document"]["permissions"]["edit"] = $editable; if (($editable || $restrictedEditing) && ($canEdit || $canFillForms)) { $ownerId = null; $owner = $file->getOwner(); diff --git a/controller/editorcontroller.php b/controller/editorcontroller.php index 871da2fa..517b73a0 100644 --- a/controller/editorcontroller.php +++ b/controller/editorcontroller.php @@ -1278,7 +1278,6 @@ public function download($fileId, $toExtension = null, $template = false) { * @param string $shareToken - access token * @param integer $version - file version * @param bool $inframe - open in frame - * @param bool $forceEdit - open editing * @param bool $template - file is template * @param string $anchor - anchor for file content * @@ -1287,7 +1286,7 @@ public function download($fileId, $toExtension = null, $template = false) { * @NoAdminRequired * @NoCSRFRequired */ - public function index($fileId, $filePath = null, $shareToken = null, $version = 0, $inframe = false, $forceEdit = false, $template = false, $anchor = null) { + public function index($fileId, $filePath = null, $shareToken = null, $version = 0, $inframe = false, $template = false, $anchor = null) { $this->logger->debug("Open: $fileId ($version) $filePath", ["app" => $this->appName]); if (empty($shareToken) && !$this->userSession->isLoggedIn()) { @@ -1327,8 +1326,7 @@ public function index($fileId, $filePath = null, $shareToken = null, $version = "version" => $version, "template" => $template, "inframe" => false, - "anchor" => $anchor, - "forceEdit" => $forceEdit + "anchor" => $anchor ]; if ($inframe === true) { @@ -1359,7 +1357,6 @@ public function index($fileId, $filePath = null, $shareToken = null, $version = * @param string $shareToken - access token * @param integer $version - file version * @param bool $inframe - open in frame - * @param bool $forceEdit - open editing * * @return TemplateResponse * @@ -1367,8 +1364,8 @@ public function index($fileId, $filePath = null, $shareToken = null, $version = * @NoCSRFRequired * @PublicPage */ - public function publicPage($fileId, $shareToken, $version = 0, $inframe = false, $forceEdit = false) { - return $this->index($fileId, null, $shareToken, $version, $inframe, $forceEdit); + public function publicPage($fileId, $shareToken, $version = 0, $inframe = false) { + return $this->index($fileId, null, $shareToken, $version, $inframe); } /** diff --git a/css/editor.css b/css/editor.css index d2533d7d..cb92d61f 100644 --- a/css/editor.css +++ b/css/editor.css @@ -17,19 +17,22 @@ */ #app > iframe { - position: absolute; - vertical-align: top; + position: absolute; + vertical-align: top; } + #body-public #content { - height: 100%; + height: 100%; } + #content-wrapper #content { - height: calc(100dvh - 45px); + height: calc(100dvh - 45px); } .AscDesktopEditor #header { - display: none; + display: none; } + .AscDesktopEditor #content-wrapper { - padding-top: 0; + padding-top: 0; } diff --git a/css/main.css b/css/main.css index 6a7787ea..c6fe679f 100644 --- a/css/main.css +++ b/css/main.css @@ -17,77 +17,91 @@ */ .icon-onlyoffice-new-docx { - background-image: url("../img/new-docx.svg"); + background-image: url("../img/new-docx.svg"); } + .icon-onlyoffice-new-xlsx { - background-image: url("../img/new-xlsx.svg"); + background-image: url("../img/new-xlsx.svg"); } + .icon-onlyoffice-new-pptx { - background-image: url("../img/new-pptx.svg"); + background-image: url("../img/new-pptx.svg"); } + .icon-onlyoffice-new-pdf { - background-image: url("../img/new-pdf.svg"); + background-image: url("../img/new-pdf.svg"); } + .icon-onlyoffice-open, .icon-onlyoffice-convert, .icon-onlyoffice-download, .icon-onlyoffice-create { - background-image: url("../img/app-dark.svg"); + background-image: url("../img/app-dark.svg"); +} + +.AscDesktopEditor #content-wrapper { + padding-top: 0; +} + +.AscDesktopEditor #controls, +.AscDesktopEditor #app-sidebar { + top: 0; } /* onlyoffice-inline */ body.onlyoffice-inline #content-wrapper { - overscroll-behavior-y: none; - overflow: hidden; + overflow: hidden; + overscroll-behavior-y: none; } + body.onlyoffice-inline #app-navigation, body.onlyoffice-inline .searchbox, body.onlyoffice-inline #app-content #controls { - display: none; + display: none; } + body.onlyoffice-inline #app-navigation-toggle { - display: none !important; + display: none !important; } + body.onlyoffice-inline #content #app-content { - margin-left: 0; - overflow: hidden; + margin-left: 0; + overflow: hidden; } -#onlyofficeFrame { - background-color: #fff; - width: 100%; - height: calc(100vh - 45px); - display: block; - position: absolute; - top: 0; - z-index: 110; + +#onlyoffice-frame { + background-color: #fff; + display: block; + height: calc(100vh - 45px); + position: absolute; + top: 0; + width: 100%; + z-index: 110; } .onlyoffice-public-open { - display: inline-block; - margin-top: 10px; + display: inline-block; + margin-top: 10px; } /* AscDesktopEditor */ .AscDesktopEditor #header { - display: none; -} -.AscDesktopEditor #content-wrapper { - padding-top: 0; -} -.AscDesktopEditor #controls, -.AscDesktopEditor #app-sidebar { - top: 0; + display: none; } + .AscDesktopEditor #body-user table.multiselect thead { - top: 44px; + top: 44px; } + .AscDesktopEditor #body-user #gallery-button { - display: none; + display: none; } + .onlyoffice-download-container { - display: flex; + display: flex; } + .onlyoffice-download-container p { - margin-right: 10px; - padding-top: 10px; + margin-right: 10px; + padding-top: 10px; } diff --git a/css/settings.css b/css/settings.css index 8292bef7..b6fe77bd 100644 --- a/css/settings.css +++ b/css/settings.css @@ -17,147 +17,167 @@ */ #content .section-onlyoffice h2 .icon-info { - padding-top: 17px; + padding-top: 17px; } + .onlyoffice-error { - color: red; + color: #f00; } + .onlyoffice-header { - display: inline-block; - margin-top: 16px; + display: inline-block; + margin-top: 16px; } + .section-onlyoffice input { - display: block; - width: 250px; + display: block; + width: 250px; } + .onlyoffice-hide { - display: none; + display: none; } -#onlyofficeAdv { - cursor: pointer; - text-decoration: none; + +#onlyoffice-adv { + cursor: pointer; + text-decoration: none; } -#onlyofficeAdv .icon { - display: inline-block; - margin-bottom: -3px; + +#onlyoffice-adv .icon { + display: inline-block; + margin-bottom: -3px; } -#onlyofficeAddrSave { - float: left; + +#onlyoffice-addr-save { + float: left; } -#onlyofficeSave { - margin-bottom: 25px; + +#onlyoffice-save { + margin-bottom: 25px; } + .onlyoffice-demo { - margin-left: 90px; + margin-left: 90px; } -#s2id_onlyofficeLimitGroups { - margin-bottom: 16px; + +#s2i-onlyoffice-limit-groups { + margin-bottom: 16px; } + .onlyoffice-exts { - column-width: 100px; - -moz-column-width: 100px; - -webkit-column-width: 100px; + -moz-column-width: 100px; + -webkit-column-width: 100px; + column-width: 100px; } + .onlyoffice-tables { - column-width: 140px; - -moz-column-width: 140px; - -webkit-column-width: 140px; + -moz-column-width: 140px; + -webkit-column-width: 140px; + column-width: 140px; } + #personal-show + label { - margin-top: -25px; - margin-left: 230px; + margin-left: 230px; + margin-top: -25px; } + .onlyoffice-option-desc { - margin-left: 20px; + margin-left: 20px; } -#onlyofficeDocsCloudBannerWrapper { - max-width: 596px; - min-height: 108px; - text-align: center; - background-image: url("../img/get-editors-background.svg"); - background-repeat: no-repeat; - background-color: #FFFFFF; - border: 1px solid #EFEFEF; - border-radius: 3px; - display: flex; - flex-direction: row; - margin-top: 10px; + +#onlyoffice-docscloud-banner-wrapper { + background-color: #fff; + background-image: url("../img/get-editors-background.svg"); + background-repeat: no-repeat; + border: 1px solid #efefef; + border-radius: 3px; + display: flex; + flex-direction: row; + margin-top: 10px; + max-width: 596px; + min-height: 108px; + text-align: center; } -#onlyofficeDocsCloudBannerPicWrapper { - height: 100%; - width: 20%; - padding: 10px 0 0 20px; +#onlyoffice-docscloud-banner-pic-wrapper { + height: 100%; + padding: 10px 0 0 20px; + width: 20%; } -#onlyofficeDocsCloudBannerPic { - content: url("../img/get-editors-pic.svg"); +#onlyoffice-docscloud-banner-pic { + content: url("../img/get-editors-pic.svg"); } -#onlyofficeDocsCloudBannerContent { - height: 100%; - width: 80%; - color: #000000; - display: flex; - flex-direction: row; - margin: auto; +#onlyoffice-docscloud-banner-content { + color: #000; + display: flex; + flex-direction: row; + height: 100%; + margin: auto; + width: 80%; } -#onlyofficeDocsCloudBannerContentText { - width: 60%; - height: 100%; - color: #000; - font-size: 14px; - text-align: justify; - padding-left: 15px; +#onlyoffice-docscloud-banner-content-text { + color: #000; + font-size: 14px; + height: 100%; + padding-left: 15px; + text-align: justify; + width: 60%; } -#onlyofficeDocsCloudBannerContentText h2 { - margin: 0; - color: #000000; +#onlyoffice-docscloud-banner-content-text h2 { + color: #000; + margin: 0; } -#onlyofficeDocsCloudBannerContentButtonWrapper { - width: 40%; - height: 100%; - margin: auto; +#onlyoffice-docscloud-banner-content-button-wrapper { + height: 100%; + margin: auto; + width: 40%; } -#onlyofficeDocsCloudBannerContentButton { - background-color: #EDEDED; - color: #000; - border: 1px solid #DBDBDB; +#onlyoffice-docscloud-banner-content-button { + background-color: #ededed; + border: 1px solid #dbdbdb; + color: #000; } @media (max-width: 580px) { - #onlyofficeDocsCloudBannerPicWrapper { - padding: 20px 0 0 5px; - width: 30%; - } - #onlyofficeDocsCloudBannerContent { - flex-direction: column; - width: 70%; - } - #onlyofficeDocsCloudBannerContentText { - width: 100%; - padding-right: 5px; - } - #onlyofficeDocsCloudBannerContentButtonWrapper { - width: 100%; - padding: 15px 0 15px 15px; - text-align: left; - } + #onlyoffice-docscloud-banner-pic-wrapper { + padding: 20px 0 0 5px; + width: 30%; + } + + #onlyoffice-docscloud-banner-content { + flex-direction: column; + width: 70%; + } + + #onlyoffice-docscloud-banner-content-text { + padding-right: 5px; + width: 100%; + } + + #onlyoffice-docscloud-banner-content-button-wrapper { + padding: 15px 0 15px 15px; + text-align: left; + width: 100%; + } } @media (max-width: 335px) { - #onlyofficeDocsCloudBannerWrapper { - flex-direction: column; - } - #onlyofficeDocsCloudBannerPicWrapper { - width: 100%; - padding: unset; - } - #onlyofficeDocsCloudBannerContent { - width: 100%; - } -} \ No newline at end of file + #onlyoffice-docscloud-banner-wrapper { + flex-direction: column; + } + + #onlyoffice-docscloud-banner-pic-wrapper { + padding: unset; + width: 100%; + } + + #onlyoffice-docscloud-banner-content { + width: 100%; + } +} diff --git a/css/template.css b/css/template.css index 3e7505d6..e450de5f 100644 --- a/css/template.css +++ b/css/template.css @@ -17,56 +17,67 @@ */ .onlyoffice-template-container { - margin-left: 0px !important; - max-width: 500px; + margin-left: 0 !important; + max-width: 500px; } + .onlyoffice-template-container li { - height: 27px; - padding-top: 5px; + height: 27px; + padding-top: 5px; } + .onlyoffice-template-container.container-dialog li:hover, .onlyoffice-template-item.selected { - background-color: rgb(230, 230, 230); + background-color: rgb(230 230 230); } + .onlyoffice-template-item img, .onlyoffice-template-item p, .onlyoffice-template-delete, .onlyoffice-template-download { - display: inline-block; - margin-right: 10px; - cursor: pointer; + cursor: pointer; + display: inline-block; + margin-right: 10px; } + .onlyoffice-template-item.item-dialog { - padding-left: 5px; + padding-left: 5px; } + .onlyoffice-template-delete, .onlyoffice-template-download { - margin-bottom: 2px; - opacity: .8; + margin-bottom: 2px; + opacity: 0.8; } + .onlyoffice-template-item p { - max-width: 400px; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; + max-width: 400px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } + .onlyoffice-template-item img { - float: left; - margin-top: 3px; + float: left; + margin-top: 3px; } + .onlyoffice-template-item.selected label { - color: rgb(55, 137, 243); + color: rgb(55 137 243); } + .onlyoffice-template-download { - background-image: url("../../../core/img/actions/download.svg"); - height: 16px; - width: 16px; + background-image: url("../../../core/img/actions/download.svg"); + height: 16px; + width: 16px; } + .onlyoffice-template.icon-add { - opacity: 0.5; - padding-left: 35px; - padding-bottom: 5px; + opacity: 0.5; + padding-bottom: 5px; + padding-left: 35px; } + .onlyoffice-template.icon-add:hover { - opacity: 0.7; -} \ No newline at end of file + opacity: 0.7; +} diff --git a/js/desktop.js b/js/desktop.js index b7747dcb..88b599c8 100644 --- a/js/desktop.js +++ b/js/desktop.js @@ -17,26 +17,24 @@ */ (function (OCA) { + OCA.Onlyoffice = _.extend({}, OCA.Onlyoffice); - OCA.Onlyoffice = _.extend({}, OCA.Onlyoffice); + if (!window["AscDesktopEditor"]) { + return; + } - if (!window["AscDesktopEditor"]) { - return; - } + OCA.Onlyoffice.Desktop = true; + $("html").addClass("AscDesktopEditor"); - OCA.Onlyoffice.Desktop = true; - $("html").addClass("AscDesktopEditor"); + let domain = new RegExp("^http(s)?://[^/]+").exec(location)[0]; + domain += OC.getRootPath(); - var domain = new RegExp("^http(s)?:\/\/[^\/]+").exec(location)[0]; - domain += OC.getRootPath(); - - var data = { - displayName: oc_user.displayName, - domain: domain, - email: oc_user.email, - provider: "ownCloud", - }; - - window.AscDesktopEditor.execCommand("portal:login", JSON.stringify(data)); + const data = { + displayName: oc_user.displayName, + domain, + email: oc_user.email, + provider: "ownCloud", + }; + window.AscDesktopEditor.execCommand("portal:login", JSON.stringify(data)); })(OCA); diff --git a/js/editor.js b/js/editor.js index 087218c8..0ec644c1 100644 --- a/js/editor.js +++ b/js/editor.js @@ -17,724 +17,865 @@ */ (function ($, OCA) { + OCA.Onlyoffice = _.extend( + { + AppName: "onlyoffice", + inframe: false, + fileId: null, + shareToken: null, + insertImageType: null, + }, + OCA.Onlyoffice + ); + + OCA.Onlyoffice.InitEditor = function () { + OCA.Onlyoffice.fileId = $("#iframeEditor").data("id"); + const filePath = $("#iframeEditor").data("path"); + OCA.Onlyoffice.shareToken = $("#iframeEditor").data("sharetoken"); + OCA.Onlyoffice.version = $("#iframeEditor").data("version"); + OCA.Onlyoffice.template = $("#iframeEditor").data("template"); + OCA.Onlyoffice.inframe = !!$("#iframeEditor").data("inframe"); + OCA.Onlyoffice.anchor = $("#iframeEditor").attr("data-anchor"); + OCA.Onlyoffice.currentWindow = window; + + if (OCA.Onlyoffice.inframe) { + OCA.Onlyoffice.faviconBase = $('link[rel="icon"]').attr("href"); + OCA.Onlyoffice.currentWindow = window.parent; + OCA.Onlyoffice.titleBase = OCA.Onlyoffice.currentWindow.document.title; + } - OCA.Onlyoffice = _.extend({ - AppName: "onlyoffice", - inframe: false, - fileId: null, - shareToken: null, - insertImageType: null - }, OCA.Onlyoffice); - - OCA.Onlyoffice.InitEditor = function () { - - OCA.Onlyoffice.fileId = $("#iframeEditor").data("id"); - var filePath = $("#iframeEditor").data("path"); - OCA.Onlyoffice.shareToken = $("#iframeEditor").data("sharetoken"); - OCA.Onlyoffice.version = $("#iframeEditor").data("version"); - OCA.Onlyoffice.template = $("#iframeEditor").data("template"); - OCA.Onlyoffice.inframe = !!$("#iframeEditor").data("inframe"); - OCA.Onlyoffice.anchor = $("#iframeEditor").attr("data-anchor"); - OCA.Onlyoffice.forceEdit = $("#iframeEditor").attr("data-forceEdit"); - OCA.Onlyoffice.currentWindow = window; - - if (OCA.Onlyoffice.inframe) { - OCA.Onlyoffice.faviconBase = $('link[rel="icon"]').attr("href"); - OCA.Onlyoffice.currentWindow = window.parent; - OCA.Onlyoffice.titleBase = OCA.Onlyoffice.currentWindow.document.title; - } - - if (!OCA.Onlyoffice.fileId && !OCA.Onlyoffice.shareToken) { - OCA.Onlyoffice.showMessage(t(OCA.Onlyoffice.AppName, "FileId is empty"), {type: "error"}); - return; - } - - if (typeof DocsAPI === "undefined") { - OCA.Onlyoffice.showMessage(t(OCA.Onlyoffice.AppName, "ONLYOFFICE cannot be reached. Please contact admin"), {type: "error"}); - return; - } - - var docsVersion = DocsAPI.DocEditor.version().split("."); - if (docsVersion[0] < 6 - || docsVersion[0] == 6 && docsVersion[1] == 0) { - OCA.Onlyoffice.showMessage(t(OCA.Onlyoffice.AppName, "Not supported version"), "error", {timeout: -1}); - return; - } + if (!OCA.Onlyoffice.fileId && !OCA.Onlyoffice.shareToken) { + OCA.Onlyoffice.showMessage(t(OCA.Onlyoffice.AppName, "FileId is empty"), { + type: "error", + }); + return; + } - var configUrl = OC.linkToOCS("apps/" + OCA.Onlyoffice.AppName + "/api/v1/config", 2) + (OCA.Onlyoffice.fileId || 0); + if (typeof DocsAPI === "undefined") { + OCA.Onlyoffice.showMessage( + t( + OCA.Onlyoffice.AppName, + "ONLYOFFICE cannot be reached. Please contact admin" + ), + { type: "error" } + ); + return; + } - var params = []; - if (filePath) { - params.push("filePath=" + encodeURIComponent(filePath)); - } - if (OCA.Onlyoffice.shareToken) { - params.push("shareToken=" + encodeURIComponent(OCA.Onlyoffice.shareToken)); - } - if (OCA.Onlyoffice.version > 0) { - params.push("version=" + OCA.Onlyoffice.version); - } - if (OCA.Onlyoffice.template) { - params.push("template=true"); - } + const docsVersion = DocsAPI.DocEditor.version().split("."); + if ( + docsVersion[0] < 6 || + (parseInt(docsVersion[0]) === 6 && parseInt(docsVersion[1]) === 0) + ) { + OCA.Onlyoffice.showMessage( + t(OCA.Onlyoffice.AppName, "Not supported version"), + "error", + { timeout: -1 } + ); + return; + } - if (OCA.Onlyoffice.inframe) { - params.push("inframe=true"); - } + let configUrl = + OC.linkToOCS("apps/" + OCA.Onlyoffice.AppName + "/api/v1/config", 2) + + (OCA.Onlyoffice.fileId || 0); - if (OCA.Onlyoffice.anchor) { - params.push("anchor=" + encodeURIComponent(OCA.Onlyoffice.anchor)); - } + const params = []; + if (filePath) { + params.push("filePath=" + encodeURIComponent(filePath)); + } + if (OCA.Onlyoffice.shareToken) { + params.push( + "shareToken=" + encodeURIComponent(OCA.Onlyoffice.shareToken) + ); + } + if (OCA.Onlyoffice.version > 0) { + params.push("version=" + OCA.Onlyoffice.version); + } + if (OCA.Onlyoffice.template) { + params.push("template=true"); + } - if (OCA.Onlyoffice.forceEdit) { - params.push("forceEdit=true"); - } + if (OCA.Onlyoffice.inframe) { + params.push("inframe=true"); + } - if (OCA.Onlyoffice.Desktop) { - params.push("desktop=true"); - } - if (params.length) { - configUrl += "?" + params.join("&"); - } + if (OCA.Onlyoffice.anchor) { + params.push("anchor=" + encodeURIComponent(OCA.Onlyoffice.anchor)); + } - $.ajax({ - url: configUrl, - success: function onSuccess(config) { - if (config) { - if (config.error != null) { - OCA.Onlyoffice.showMessage(config.error, {type: "error"}); - return; - } - OCA.Onlyoffice.device = config.type; - if (OCA.Onlyoffice.device === "mobile") { - OCA.Onlyoffice.resizeEvents(); - } - - var docIsChanged = null; - var docIsChangedTimeout = null; - - var setPageTitle = function (event) { - clearTimeout(docIsChangedTimeout); - - if (docIsChanged !== event.data) { - var titleChange = function () { - OCA.Onlyoffice.currentWindow.document.title = config.document.title + (event.data ? " *" : "") + " - " + oc_defaults.title; - docIsChanged = event.data; - }; - - if (event === false || event.data) { - titleChange(); - } else { - docIsChangedTimeout = setTimeout(titleChange, 500); - } - } - }; - setPageTitle(false); - - OCA.Onlyoffice.documentType = config.documentType; - - config.events = { - "onDocumentStateChange": setPageTitle, - "onDocumentReady": OCA.Onlyoffice.onDocumentReady, - "onMakeActionLink": OCA.Onlyoffice.onMakeActionLink, - }; - - if (config.editorConfig.tenant) { - config.events.onAppReady = function () { - OCA.Onlyoffice.docEditor.showMessage(t(OCA.Onlyoffice.AppName, "You are using public demo ONLYOFFICE Docs server. Please do not store private sensitive data.")); - }; - } - - if (OCA.Onlyoffice.inframe && !OCA.Onlyoffice.shareToken - || OC.currentUser) { - config.events.onRequestSaveAs = OCA.Onlyoffice.onRequestSaveAs; - config.events.onRequestInsertImage = OCA.Onlyoffice.onRequestInsertImage; - config.events.onRequestMailMergeRecipients = OCA.Onlyoffice.onRequestMailMergeRecipients; - config.events.onRequestSelectDocument = OCA.Onlyoffice.onRequestSelectDocument; - config.events.onRequestCompareFile = OCA.Onlyoffice.onRequestSelectDocument; //todo: remove (for editors 7.4) - config.events.onRequestSendNotify = OCA.Onlyoffice.onRequestSendNotify; - config.events.onRequestReferenceData = OCA.Onlyoffice.onRequestReferenceData; - config.events.onRequestOpen = OCA.Onlyoffice.onRequestOpen; - config.events.onRequestReferenceSource = OCA.Onlyoffice.onRequestReferenceSource; - config.events.onMetaChange = OCA.Onlyoffice.onMetaChange; - - if (OC.currentUser) { - config.events.onRequestUsers = OCA.Onlyoffice.onRequestUsers; - } - - if (!OCA.Onlyoffice.filePath) { - OCA.Onlyoffice.filePath = config._file_path; - } - - if (!OCA.Onlyoffice.template) { - config.events.onRequestHistory = OCA.Onlyoffice.onRequestHistory; - config.events.onRequestHistoryData = OCA.Onlyoffice.onRequestHistoryData; - config.events.onRequestRestore = OCA.Onlyoffice.onRequestRestore; - - if (!OCA.Onlyoffice.version) { - config.events.onRequestHistoryClose = OCA.Onlyoffice.onRequestHistoryClose; - } - } - } - - if (OCA.Onlyoffice.inframe) { - config.events.onRequestClose = OCA.Onlyoffice.onRequestClose; - } - - if (OCA.Onlyoffice.inframe - && config._files_sharing && !OCA.Onlyoffice.shareToken - && window.parent.OCA.Onlyoffice.context) { - config.events.onRequestSharingSettings = OCA.Onlyoffice.onRequestSharingSettings; - } - - if (!config.document.permissions.edit - && config.document.permissions.fillForms - && config.canEdit) { - config.events.onRequestEditRights = OCA.Onlyoffice.onRequestEditRights; - } - - OCA.Onlyoffice.docEditor = new DocsAPI.DocEditor("iframeEditor", config); - - if (config.type === "mobile" && $("#app > iframe").css("position") === "fixed" - && !OCA.Onlyoffice.inframe) { - $("#app > iframe").css("height", "calc(100% - 45px)"); - } - - var favicon = OC.filePath(OCA.Onlyoffice.AppName, "img", OCA.Onlyoffice.documentType + ".ico"); - if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "changeFavicon", - param: favicon - }, - "*"); - } else { - $('link[rel="icon"]').attr("href", favicon); - } - } - } - }); - }; + if (OCA.Onlyoffice.Desktop) { + params.push("desktop=true"); + } + if (params.length) { + configUrl += "?" + params.join("&"); + } - OCA.Onlyoffice.onRequestEditRights = function () { - if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "onRequestEditRights" - }, - "*"); + $.ajax({ + url: configUrl, + success: function onSuccess(config) { + if (config) { + if (config.error != null) { + OCA.Onlyoffice.showMessage(config.error, { type: "error" }); return; - } - location.href += "&forceEdit=true"; - }; - - OCA.Onlyoffice.onRequestHistory = function (version) { - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/history?fileId={fileId}", - { - fileId: OCA.Onlyoffice.fileId || 0, - }), - function onSuccess(response) { - OCA.Onlyoffice.refreshHistory(response, version); - }); - }; - - OCA.Onlyoffice.onRequestHistoryData = function (event) { - var version = event.data; - - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/version?fileId={fileId}&version={version}", - { - fileId: OCA.Onlyoffice.fileId || 0, - version: version, - }), - function onSuccess(response) { - if (response.error) { - response = { - error: response.error, - version: version, - }; - } - OCA.Onlyoffice.docEditor.setHistoryData(response); - }); - }; - - OCA.Onlyoffice.onRequestRestore = function (event) { - var version = event.data.version; + } + OCA.Onlyoffice.device = config.type; + if (OCA.Onlyoffice.device === "mobile") { + OCA.Onlyoffice.resizeEvents(); + } + + let docIsChanged = null; + let docIsChangedTimeout = null; + + const setPageTitle = function (event) { + clearTimeout(docIsChangedTimeout); + + if (docIsChanged !== event.data) { + const titleChange = function () { + OCA.Onlyoffice.currentWindow.document.title = + config.document.title + + (event.data ? " *" : "") + + " - " + + oc_defaults.title; + docIsChanged = event.data; + }; + + if (event === false || event.data) { + titleChange(); + } else { + docIsChangedTimeout = setTimeout(titleChange, 500); + } + } + }; + setPageTitle(false); + + OCA.Onlyoffice.documentType = config.documentType; + + config.events = { + onDocumentStateChange: setPageTitle, + onDocumentReady: OCA.Onlyoffice.onDocumentReady, + onMakeActionLink: OCA.Onlyoffice.onMakeActionLink, + }; + + if (config.editorConfig.tenant) { + config.events.onAppReady = function () { + OCA.Onlyoffice.docEditor.showMessage( + t( + OCA.Onlyoffice.AppName, + "You are using public demo ONLYOFFICE Docs server. Please do not store private sensitive data." + ) + ); + }; + } + + if ( + (OCA.Onlyoffice.inframe && !OCA.Onlyoffice.shareToken) || + OC.currentUser + ) { + config.events.onRequestSaveAs = OCA.Onlyoffice.onRequestSaveAs; + config.events.onRequestInsertImage = + OCA.Onlyoffice.onRequestInsertImage; + config.events.onRequestMailMergeRecipients = + OCA.Onlyoffice.onRequestMailMergeRecipients; + config.events.onRequestSelectDocument = + OCA.Onlyoffice.onRequestSelectDocument; + config.events.onRequestCompareFile = + OCA.Onlyoffice.onRequestSelectDocument; //todo: remove (for editors 7.4) + config.events.onRequestSendNotify = + OCA.Onlyoffice.onRequestSendNotify; + config.events.onRequestReferenceData = + OCA.Onlyoffice.onRequestReferenceData; + config.events.onRequestOpen = OCA.Onlyoffice.onRequestOpen; + config.events.onRequestReferenceSource = + OCA.Onlyoffice.onRequestReferenceSource; + config.events.onMetaChange = OCA.Onlyoffice.onMetaChange; + + if (OC.currentUser) { + config.events.onRequestUsers = OCA.Onlyoffice.onRequestUsers; + } - $.ajax({ - method: "PUT", - url: OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/restore"), - data: { - fileId: OCA.Onlyoffice.fileId || 0, - version: version, - }, - success: function onSuccess(response) { - OCA.Onlyoffice.refreshHistory(response, version); - - if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "onRefreshVersionsDialog" - }, - "*"); - } + if (!OCA.Onlyoffice.filePath) { + OCA.Onlyoffice.filePath = config._file_path; } - }) - }; - OCA.Onlyoffice.onRequestHistoryClose = function () { - location.reload(true); - }; + if (!OCA.Onlyoffice.template) { + config.events.onRequestHistory = OCA.Onlyoffice.onRequestHistory; + config.events.onRequestHistoryData = + OCA.Onlyoffice.onRequestHistoryData; + config.events.onRequestRestore = OCA.Onlyoffice.onRequestRestore; - OCA.Onlyoffice.onDocumentReady = function() { - if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "onDocumentReady", - param: OCA.Onlyoffice.documentType - }, - "*"); + if (!OCA.Onlyoffice.version) { + config.events.onRequestHistoryClose = + OCA.Onlyoffice.onRequestHistoryClose; + } + } + } + + if (OCA.Onlyoffice.inframe) { + config.events.onRequestClose = OCA.Onlyoffice.onRequestClose; + } + + if ( + OCA.Onlyoffice.inframe && + config._files_sharing && + !OCA.Onlyoffice.shareToken && + window.parent.OCA.Onlyoffice.context + ) { + config.events.onRequestSharingSettings = + OCA.Onlyoffice.onRequestSharingSettings; + } + + OCA.Onlyoffice.docEditor = new DocsAPI.DocEditor( + "iframeEditor", + config + ); + + if ( + config.type === "mobile" && + $("#app > iframe").css("position") === "fixed" && + !OCA.Onlyoffice.inframe + ) { + $("#app > iframe").css("height", "calc(100% - 45px)"); + } + + const favicon = OC.filePath( + OCA.Onlyoffice.AppName, + "img", + OCA.Onlyoffice.documentType + ".ico" + ); + if (OCA.Onlyoffice.inframe) { + window.parent.postMessage( + { + method: "changeFavicon", + param: favicon, + }, + "*" + ); + } else { + $('link[rel="icon"]').attr("href", favicon); + } } - - if (OCA.Onlyoffice.version > 0) { - OCA.Onlyoffice.onRequestHistory(OCA.Onlyoffice.version); + }, + }); + }; + + OCA.Onlyoffice.onRequestHistory = function (version) { + $.get( + OC.generateUrl( + "apps/" + OCA.Onlyoffice.AppName + "/ajax/history?fileId={fileId}", + { + fileId: OCA.Onlyoffice.fileId || 0, } - - OCA.Onlyoffice.resize(); - OCA.Onlyoffice.setViewport(); - }; - - OCA.Onlyoffice.onRequestSaveAs = function (event) { - var saveData = { - name: event.data.title, - url: event.data.url - }; - - if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "editorRequestSaveAs", - param: saveData - }, - "*"); - } else { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Save as"), - function (fileDir) { - saveData.dir = fileDir; - OCA.Onlyoffice.editorSaveAs(saveData); - }, - false, - "httpd/unix-directory", - true); + ), + function onSuccess(response) { + OCA.Onlyoffice.refreshHistory(response, version); + } + ); + }; + + OCA.Onlyoffice.onRequestHistoryData = function (event) { + const version = event.data; + + $.get( + OC.generateUrl( + "apps/" + + OCA.Onlyoffice.AppName + + "/ajax/version?fileId={fileId}&version={version}", + { + fileId: OCA.Onlyoffice.fileId || 0, + version, } - }; - - OCA.Onlyoffice.editorSaveAs = function (saveData) { - $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/save"), - saveData, - function onSuccess(response) { - if (response.error) { - OCA.Onlyoffice.showMessage(response.error, { - type: "error", - timeout: 3 - }); - return; - } - - OCA.Onlyoffice.showMessage(t(OCA.Onlyoffice.AppName, "File saved") + " (" + response.name + ")", { - timeout: 3 - }); - }); - }; - - OCA.Onlyoffice.onRequestInsertImage = function (event) { - var imageMimes = [ - "image/bmp", "image/x-bmp", "image/x-bitmap", "application/bmp", - "image/gif", - "image/jpeg", "image/jpg", "application/jpg", "application/x-jpg", - "image/png", "image/x-png", "application/png", "application/x-png" - ]; - - if (event.data) { - OCA.Onlyoffice.insertImageType = event.data.c; + ), + function onSuccess(response) { + if (response.error) { + response = { + error: response.error, + version, + }; } + OCA.Onlyoffice.docEditor.setHistoryData(response); + } + ); + }; + + OCA.Onlyoffice.onRequestRestore = function (event) { + const version = event.data.version; + + $.ajax({ + method: "PUT", + url: OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/restore"), + data: { + fileId: OCA.Onlyoffice.fileId || 0, + version, + }, + success: function onSuccess(response) { + OCA.Onlyoffice.refreshHistory(response, version); if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "editorRequestInsertImage", - param: imageMimes + window.parent.postMessage( + { + method: "onRefreshVersionsDialog", }, - "*"); - } else { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Insert image"), - OCA.Onlyoffice.editorInsertImage, - false, - imageMimes, - true); + "*" + ); } - }; + }, + }); + }; - OCA.Onlyoffice.editorInsertImage = function (filePath) { - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/url?filePath={filePath}", - { - filePath: filePath - }), - function onSuccess(response) { - if (response.error) { - OCA.Onlyoffice.showMessage(response.error, { - type: "error", - timeout: 3 - }); - return; - } - - if (OCA.Onlyoffice.insertImageType) { - response.c = OCA.Onlyoffice.insertImageType; - } - - OCA.Onlyoffice.docEditor.insertImage(response); - }); - }; + OCA.Onlyoffice.onRequestHistoryClose = function () { + location.reload(true); + }; - OCA.Onlyoffice.onRequestMailMergeRecipients = function () { - var recipientMimes = [ - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" - ]; + OCA.Onlyoffice.onDocumentReady = function () { + if (OCA.Onlyoffice.inframe) { + window.parent.postMessage( + { + method: "onDocumentReady", + param: OCA.Onlyoffice.documentType, + }, + "*" + ); + } - if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "editorRequestMailMergeRecipients", - param: recipientMimes - }, - "*"); - } else { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select recipients"), - OCA.Onlyoffice.editorSetRecipient, - false, - recipientMimes, - true); - } - }; + if (OCA.Onlyoffice.version > 0) { + OCA.Onlyoffice.onRequestHistory(OCA.Onlyoffice.version); + } - OCA.Onlyoffice.editorSetRecipient = function (filePath) { - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/url?filePath={filePath}", - { - filePath: filePath - }), - function onSuccess(response) { - if (response.error) { - OCA.Onlyoffice.showMessage(response.error, { - type: "error", - timeout: 3 - }); - return; - } - - OCA.Onlyoffice.docEditor.setMailMergeRecipients(response); - }); - }; + OCA.Onlyoffice.resize(); + OCA.Onlyoffice.setViewport(); + }; - OCA.Onlyoffice.editorReferenceSource = function (filePath) { - if (filePath === OCA.Onlyoffice.filePath) { - OCA.Onlyoffice.showMessage(t(OCA.Onlyoffice.AppName, "The data source must not be the current document"), "error"); - return; - } + OCA.Onlyoffice.onRequestSaveAs = function (event) { + const saveData = { + name: event.data.title, + url: event.data.url, + }; - $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/reference"), + if (OCA.Onlyoffice.inframe) { + window.parent.postMessage( { - path: filePath + method: "editorRequestSaveAs", + param: saveData, }, - function onSuccess(response) { - if (response.error) { - OCA.Onlyoffice.showMessage(response.error, "error"); - return; - } - OCA.Onlyoffice.docEditor.setReferenceSource(response); - }); + "*" + ); + } else { + OC.dialogs.filepicker( + t(OCA.Onlyoffice.AppName, "Save as"), + function (fileDir) { + saveData.dir = fileDir; + OCA.Onlyoffice.editorSaveAs(saveData); + }, + false, + "httpd/unix-directory", + true + ); } + }; - OCA.Onlyoffice.onRequestClose = function () { - OCA.Onlyoffice.docEditor.destroyEditor(); + OCA.Onlyoffice.editorSaveAs = function (saveData) { + $.post( + OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/save"), + saveData, + function onSuccess(response) { + if (response.error) { + OCA.Onlyoffice.showMessage(response.error, { + type: "error", + timeout: 3, + }); + return; + } - window.parent.postMessage({ - method: "editorRequestClose" - }, - "*"); - }; + OCA.Onlyoffice.showMessage( + t(OCA.Onlyoffice.AppName, "File saved") + " (" + response.name + ")", + { + timeout: 3, + } + ); + } + ); + }; + + OCA.Onlyoffice.onRequestInsertImage = function (event) { + const imageMimes = [ + "image/bmp", + "image/x-bmp", + "image/x-bitmap", + "application/bmp", + "image/gif", + "image/tiff", + "image/jpeg", + "image/jpg", + "application/jpg", + "application/x-jpg", + "image/png", + "image/x-png", + "application/png", + "application/x-png", + ]; + + if (event.data) { + OCA.Onlyoffice.insertImageType = event.data.c; + } - OCA.Onlyoffice.onRequestSharingSettings = function () { - window.parent.postMessage({ - method: "editorRequestSharingSettings" + if (OCA.Onlyoffice.inframe) { + window.parent.postMessage( + { + method: "editorRequestInsertImage", + param: imageMimes, }, - "*"); - }; - - OCA.Onlyoffice.onRequestSelectDocument = function (event) { - var revisedMimes = [ - "application/vnd.openxmlformats-officedocument.wordprocessingml.document" - ]; + "*" + ); + } else { + OC.dialogs.filepicker( + t(OCA.Onlyoffice.AppName, "Insert image"), + OCA.Onlyoffice.editorInsertImage, + false, + imageMimes, + true + ); + } + }; - if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "editorRequestSelectDocument", - param: revisedMimes, - documentSelectionType: event.data.c - }, - "*"); - } else { - let title; - switch (event.data.c) { - case "combine": - title = t(OCA.Onlyoffice.AppName, "Select file to combine"); - break; - default: - title = t(OCA.Onlyoffice.AppName, "Select file to compare"); - } - OC.dialogs.filepicker(title, - OCA.Onlyoffice.editorSetRequested.bind({documentSelectionType: event.data.c}), - false, - revisedMimes, - true); + OCA.Onlyoffice.editorInsertImage = function (filePath) { + $.get( + OC.generateUrl( + "apps/" + OCA.Onlyoffice.AppName + "/ajax/url?filePath={filePath}", + { + filePath, + } + ), + function onSuccess(response) { + if (response.error) { + OCA.Onlyoffice.showMessage(response.error, { + type: "error", + timeout: 3, + }); + return; } - }; - OCA.Onlyoffice.editorSetRequested = function (filePath) { - let documentSelectionType = this.documentSelectionType; - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/url?filePath={filePath}", - { - filePath: filePath - }), - function onSuccess(response) { - if (response.error) { - OCA.Onlyoffice.showMessage(response.error, { - type: "error", - timeout: 3 - }); - return; - } - response.c = documentSelectionType; - - OCA.Onlyoffice.docEditor.setRequestedDocument(response); - }); - }; + if (OCA.Onlyoffice.insertImageType) { + response.c = OCA.Onlyoffice.insertImageType; + } - OCA.Onlyoffice.onMakeActionLink = function (event) { - var url = location.href; - if (event && event.data) { - var indexAnchor = url.indexOf("#"); - if (indexAnchor != -1) { - url = url.substring(0, indexAnchor); - } + OCA.Onlyoffice.docEditor.insertImage(response); + } + ); + }; - var data = JSON.stringify(event.data); - data = "anchor=" + encodeURIComponent(data); + OCA.Onlyoffice.onRequestMailMergeRecipients = function () { + const recipientMimes = [ + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + ]; - var inframeRegex = /inframe=([^&]*&?)/g; - if (inframeRegex.test(url)) { - url = url.replace(inframeRegex, data); - } + if (OCA.Onlyoffice.inframe) { + window.parent.postMessage( + { + method: "editorRequestMailMergeRecipients", + param: recipientMimes, + }, + "*" + ); + } else { + OC.dialogs.filepicker( + t(OCA.Onlyoffice.AppName, "Select recipients"), + OCA.Onlyoffice.editorSetRecipient, + false, + recipientMimes, + true + ); + } + }; - var anchorRegex = /anchor=([^&]*)/g; - if (anchorRegex.test(url)) { - url = url.replace(anchorRegex, data); - } else { - url += (url.indexOf("?") == -1) ? "?" : "&"; - url += data; - } + OCA.Onlyoffice.editorSetRecipient = function (filePath) { + $.get( + OC.generateUrl( + "apps/" + OCA.Onlyoffice.AppName + "/ajax/url?filePath={filePath}", + { + filePath, + } + ), + function onSuccess(response) { + if (response.error) { + OCA.Onlyoffice.showMessage(response.error, { + type: "error", + timeout: 3, + }); + return; } - OCA.Onlyoffice.docEditor.setActionLink(url); - }; + OCA.Onlyoffice.docEditor.setMailMergeRecipients(response); + } + ); + }; + + OCA.Onlyoffice.editorReferenceSource = function (filePath) { + if (filePath === OCA.Onlyoffice.filePath) { + OCA.Onlyoffice.showMessage( + t( + OCA.Onlyoffice.AppName, + "The data source must not be the current document" + ), + "error" + ); + return; + } - OCA.Onlyoffice.onRequestUsers = function (event) { - let operationType = typeof(event.data.c) !== "undefined" ? event.data.c : null; - switch (operationType) { - case "info": - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/userInfo?userIds={userIds}", - { - userIds: JSON.stringify(event.data.id) - }), - function onSuccess(response) { - OCA.Onlyoffice.docEditor.setUsers({ - "c": operationType, - "users": response - }); - }); - break; - default: - $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/users?fileId={fileId}&operationType=" + operationType, - { - fileId: OCA.Onlyoffice.fileId || 0 - }), - function onSuccess(response) { - OCA.Onlyoffice.docEditor.setUsers({ - "c": operationType, - "users": response - }); - }); + $.post( + OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/reference"), + { + path: filePath, + }, + function onSuccess(response) { + if (response.error) { + OCA.Onlyoffice.showMessage(response.error, "error"); + return; } - }; + OCA.Onlyoffice.docEditor.setReferenceSource(response); + } + ); + }; + + OCA.Onlyoffice.onRequestClose = function () { + OCA.Onlyoffice.docEditor.destroyEditor(); + + window.parent.postMessage( + { + method: "editorRequestClose", + }, + "*" + ); + }; + + OCA.Onlyoffice.onRequestSharingSettings = function () { + window.parent.postMessage( + { + method: "editorRequestSharingSettings", + }, + "*" + ); + }; + + OCA.Onlyoffice.onRequestSelectDocument = function (event) { + const revisedMimes = [ + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + ]; + + if (OCA.Onlyoffice.inframe) { + window.parent.postMessage( + { + method: "editorRequestSelectDocument", + param: revisedMimes, + documentSelectionType: event.data.c, + }, + "*" + ); + } else { + let title; + switch (event.data.c) { + case "combine": + title = t(OCA.Onlyoffice.AppName, "Select file to combine"); + break; + default: + title = t(OCA.Onlyoffice.AppName, "Select file to compare"); + } + OC.dialogs.filepicker( + title, + OCA.Onlyoffice.editorSetRequested.bind({ + documentSelectionType: event.data.c, + }), + false, + revisedMimes, + true + ); + } + }; - OCA.Onlyoffice.onRequestReferenceData = function (event) { - let referenceData = event.data.referenceData; - let path = event.data.path; + OCA.Onlyoffice.editorSetRequested = function (filePath) { + const documentSelectionType = this.documentSelectionType; + $.get( + OC.generateUrl( + "apps/" + OCA.Onlyoffice.AppName + "/ajax/url?filePath={filePath}", + { + filePath, + } + ), + function onSuccess(response) { + if (response.error) { + OCA.Onlyoffice.showMessage(response.error, { + type: "error", + timeout: 3, + }); + return; + } + response.c = documentSelectionType; + + OCA.Onlyoffice.docEditor.setRequestedDocument(response); + } + ); + }; + + OCA.Onlyoffice.onMakeActionLink = function (event) { + let url = location.href; + if (event && event.data) { + const indexAnchor = url.indexOf("#"); + if (parseInt(indexAnchor) !== -1) { + url = url.substring(0, indexAnchor); + } + + let data = JSON.stringify(event.data); + data = "anchor=" + encodeURIComponent(data); + + const inframeRegex = /inframe=([^&]*&?)/g; + if (inframeRegex.test(url)) { + url = url.replace(inframeRegex, data); + } + + const anchorRegex = /anchor=([^&]*)/g; + if (anchorRegex.test(url)) { + url = url.replace(anchorRegex, data); + } else { + url += url.indexOf("?") === -1 ? "?" : "&"; + url += data; + } + } - $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/reference"), + OCA.Onlyoffice.docEditor.setActionLink(url); + }; + + OCA.Onlyoffice.onRequestUsers = function (event) { + const operationType = + typeof event.data.c !== "undefined" ? event.data.c : null; + switch (operationType) { + case "info": + $.get( + OC.generateUrl( + "apps/" + + OCA.Onlyoffice.AppName + + "/ajax/userInfo?userIds={userIds}", { - referenceData: referenceData, - path: path - }, - function onSuccess(response) { - if (response.error) { - OCA.Onlyoffice.showMessage(response.error, "error"); - return; - } - - OCA.Onlyoffice.docEditor.setReferenceData(response); + userIds: JSON.stringify(event.data.id), + } + ), + function onSuccess(response) { + OCA.Onlyoffice.docEditor.setUsers({ + c: operationType, + users: response, }); - }; - - OCA.Onlyoffice.onRequestSendNotify = function (event) { - var actionLink = event.data.actionLink; - var comment = event.data.message; - var emails = event.data.emails; - - var fileId = OCA.Onlyoffice.fileId; - - $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/mention"), + } + ); + break; + default: + $.get( + OC.generateUrl( + "apps/" + + OCA.Onlyoffice.AppName + + "/ajax/users?fileId={fileId}&operationType=" + + operationType, { - fileId: fileId, - anchor: JSON.stringify(actionLink), - comment: comment, - emails: emails - }, - function onSuccess(response) { - if (response.error) { - OCA.Onlyoffice.showMessage(response.error, { - type: "error", - timeout: 3 - }); - return; - } - - OCA.Onlyoffice.showMessage(response.message, { - timeout: 3 - }); - }); - }; - - OCA.Onlyoffice.onRequestOpen = function (event) { - let filePath = event.data.path; - let fileId = event.data.referenceData.fileKey; - let windowName = event.data.windowName; - let sourceUrl = OC.generateUrl(`apps/${OCA.Onlyoffice.AppName}/${fileId}?filePath=${OC.encodePath(filePath)}`); - window.open(sourceUrl, windowName); - }; - - OCA.Onlyoffice.onRequestReferenceSource = function (event) { - let referenceSourceMimes = [ - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" - ]; - if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "editorRequestReferenceSource", - param: referenceSourceMimes - }, - "*"); - } else { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select data source"), - OCA.Onlyoffice.editorReferenceSource, - false, - referenceSourceMimes, - true); - } - }; - - OCA.Onlyoffice.onMetaChange = function (event) { - if (event.data.favorite !== undefined) { - $.ajax({ - url: OC.generateUrl("apps/files/api/v1/files" + OC.encodePath(OCA.Onlyoffice.filePath)), - type: "post", - data: JSON.stringify({ - tags: event.data.favorite ? [OC.TAG_FAVORITE] : [] - }), - contentType: "application/json", - dataType: "json", - success: function(){ - OCA.Onlyoffice.docEditor.setFavorite(event.data.favorite); - } + fileId: OCA.Onlyoffice.fileId || 0, + } + ), + function onSuccess(response) { + OCA.Onlyoffice.docEditor.setUsers({ + c: operationType, + users: response, }); - } + } + ); } - - OCA.Onlyoffice.showMessage = function (message, props = null) { - if (OCA.Onlyoffice.inframe) { - window.parent.postMessage({ - method: "onShowMessage", - param: { - message: message, - props: props - } - }, - "*"); - return; + }; + + OCA.Onlyoffice.onRequestReferenceData = function (event) { + const referenceData = event.data.referenceData; + const path = event.data.path; + + $.post( + OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/reference"), + { + referenceData, + path, + }, + function onSuccess(response) { + if (response.error) { + OCA.Onlyoffice.showMessage(response.error, "error"); + return; } - OC.Notification.show(message, props); - }; - - OCA.Onlyoffice.refreshHistory = function (response, version) { + OCA.Onlyoffice.docEditor.setReferenceData(response); + } + ); + }; + + OCA.Onlyoffice.onRequestSendNotify = function (event) { + const actionLink = event.data.actionLink; + const comment = event.data.message; + const emails = event.data.emails; + + const fileId = OCA.Onlyoffice.fileId; + + $.post( + OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/mention"), + { + fileId, + anchor: JSON.stringify(actionLink), + comment, + emails, + }, + function onSuccess(response) { if (response.error) { - var data = {error: response.error}; - } else { - var currentVersion = 0; - $.each(response, function (i, fileVersion) { - if (fileVersion.version >= currentVersion) { - currentVersion = fileVersion.version; - } - - fileVersion.created = moment(fileVersion.created * 1000).format("L LTS"); - if (fileVersion.changes) { - $.each(fileVersion.changes, function (j, change) { - change.created = moment(change.created + "+00:00").format("L LTS"); - }); - } - }); + OCA.Onlyoffice.showMessage(response.error, { + type: "error", + timeout: 3, + }); + return; + } - if (version) { - currentVersion = Math.min(currentVersion, version); - } + OCA.Onlyoffice.showMessage(response.message, { + timeout: 3, + }); + } + ); + }; + + OCA.Onlyoffice.onRequestOpen = function (event) { + const filePath = event.data.path; + const fileId = event.data.referenceData.fileKey; + const windowName = event.data.windowName; + const sourceUrl = OC.generateUrl( + `apps/${OCA.Onlyoffice.AppName}/${fileId}?filePath=${OC.encodePath( + filePath + )}` + ); + window.open(sourceUrl, windowName); + }; + + OCA.Onlyoffice.onRequestReferenceSource = function (event) { + const referenceSourceMimes = [ + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + ]; + if (OCA.Onlyoffice.inframe) { + window.parent.postMessage( + { + method: "editorRequestReferenceSource", + param: referenceSourceMimes, + }, + "*" + ); + } else { + OC.dialogs.filepicker( + t(OCA.Onlyoffice.AppName, "Select data source"), + OCA.Onlyoffice.editorReferenceSource, + false, + referenceSourceMimes, + true + ); + } + }; + + OCA.Onlyoffice.onMetaChange = function (event) { + if (event.data.favorite !== undefined) { + $.ajax({ + url: OC.generateUrl( + "apps/files/api/v1/files" + OC.encodePath(OCA.Onlyoffice.filePath) + ), + type: "post", + data: JSON.stringify({ + tags: event.data.favorite ? [OC.TAG_FAVORITE] : [], + }), + contentType: "application/json", + dataType: "json", + success() { + OCA.Onlyoffice.docEditor.setFavorite(event.data.favorite); + }, + }); + } + }; - data = { - currentVersion: currentVersion, - history: response, - }; - } - OCA.Onlyoffice.docEditor.refreshHistory(data); + OCA.Onlyoffice.showMessage = function (message, props = null) { + if (OCA.Onlyoffice.inframe) { + window.parent.postMessage( + { + method: "onShowMessage", + param: { + message, + props, + }, + }, + "*" + ); + return; } - OCA.Onlyoffice.resize = function () { - if (OCA.Onlyoffice.device !== "mobile") { - return; + OC.Notification.show(message, props); + }; + + OCA.Onlyoffice.refreshHistory = function (response, version) { + let data = null; + if (response.error) { + data = { error: response.error }; + } else { + let currentVersion = 0; + $.each(response, function (i, fileVersion) { + if (fileVersion.version >= currentVersion) { + currentVersion = fileVersion.version; } - var headerHeight = $("#header").length > 0 ? $("#header").height() : 45; - var wrapEl = $("#app>iframe"); - if (wrapEl.length > 0) { - wrapEl[0].style.height = (screen.availHeight - headerHeight) + "px"; - window.scrollTo(0, -1); - wrapEl[0].style.height = (window.top.innerHeight - headerHeight) + "px"; + fileVersion.created = moment(fileVersion.created * 1000).format( + "L LTS" + ); + if (fileVersion.changes) { + $.each(fileVersion.changes, function (j, change) { + change.created = moment(change.created + "+00:00").format("L LTS"); + }); } - }; + }); - OCA.Onlyoffice.resizeEvents = function() { - if (window.addEventListener) { - if (/Android/i.test(navigator.userAgent)) { - window.addEventListener("resize", OCA.Onlyoffice.resize); - } - if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { - window.addEventListener("orientationchange", OCA.Onlyoffice.resize); - } - } - }; + if (version) { + currentVersion = Math.min(currentVersion, version); + } - OCA.Onlyoffice.setViewport = function() { - document.querySelector('meta[name="viewport"]').setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"); - }; + data = { + currentVersion, + history: response, + }; + } + OCA.Onlyoffice.docEditor.refreshHistory(data); + }; - $(document).ready(OCA.Onlyoffice.InitEditor); + OCA.Onlyoffice.resize = function () { + if (OCA.Onlyoffice.device !== "mobile") { + return; + } + const headerHeight = $("#header").length > 0 ? $("#header").height() : 45; + const wrapEl = $("#app>iframe"); + if (wrapEl.length > 0) { + wrapEl[0].style.height = screen.availHeight - headerHeight + "px"; + window.scrollTo(0, -1); + wrapEl[0].style.height = window.top.innerHeight - headerHeight + "px"; + } + }; + + OCA.Onlyoffice.resizeEvents = function () { + if (window.addEventListener) { + if (/Android/i.test(navigator.userAgent)) { + window.addEventListener("resize", OCA.Onlyoffice.resize); + } + if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { + window.addEventListener("orientationchange", OCA.Onlyoffice.resize); + } + } + }; + + OCA.Onlyoffice.setViewport = function () { + document + .querySelector('meta[name="viewport"]') + .setAttribute( + "content", + "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" + ); + }; + + $(document).ready(OCA.Onlyoffice.InitEditor); })(jQuery, OCA); diff --git a/js/listener.js b/js/listener.js index 736632cd..4a9d87f7 100644 --- a/js/listener.js +++ b/js/listener.js @@ -17,160 +17,199 @@ */ (function (OCA) { - - OCA.Onlyoffice = _.extend({ - AppName: "onlyoffice", - }, OCA.Onlyoffice); - - OCA.Onlyoffice.onRequestClose = function () { - - $("#onlyofficeFrame").remove(); - - OCA.Onlyoffice.CloseEditor(); - }; - - OCA.Onlyoffice.onRequestSaveAs = function (saveData) { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Save as"), - function (fileDir) { - saveData.dir = fileDir; - $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSaveAs(saveData); - }, - false, - "httpd/unix-directory", - true); - }; - - OCA.Onlyoffice.onRequestInsertImage = function (imageMimes) { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Insert image"), - $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorInsertImage, - false, - imageMimes, - true); - }; - - OCA.Onlyoffice.onRequestMailMergeRecipients = function (recipientMimes) { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select recipients"), - $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSetRecipient, - false, - recipientMimes, - true); - }; - - OCA.Onlyoffice.onRequestSelectDocument = function (revisedMimes, documentSelectionType) { - let title; - switch (documentSelectionType) { - case "combine": - title = t(OCA.Onlyoffice.AppName, "Select file to combine"); - break; - default: - title = t(OCA.Onlyoffice.AppName, "Select file to compare"); - } - OC.dialogs.filepicker(title, - $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSetRequested.bind({documentSelectionType: documentSelectionType}), - false, - revisedMimes, - true); - }; - - OCA.Onlyoffice.onRequestReferenceSource = function (referenceSourceMimes) { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select data source"), - $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorReferenceSource, - false, - referenceSourceMimes, - true); + OCA.Onlyoffice = _.extend( + { + AppName: "onlyoffice", + }, + OCA.Onlyoffice + ); + + OCA.Onlyoffice.onRequestClose = function () { + $("#onlyoffice-frame").remove(); + + OCA.Onlyoffice.CloseEditor(); + }; + + OCA.Onlyoffice.onRequestSaveAs = function (saveData) { + OC.dialogs.filepicker( + t(OCA.Onlyoffice.AppName, "Save as"), + function (fileDir) { + saveData.dir = fileDir; + $("#onlyoffice-frame")[0].contentWindow.OCA.Onlyoffice.editorSaveAs( + saveData + ); + }, + false, + "httpd/unix-directory", + true + ); + }; + + OCA.Onlyoffice.onRequestInsertImage = function (imageMimes) { + OC.dialogs.filepicker( + t(OCA.Onlyoffice.AppName, "Insert image"), + $("#onlyoffice-frame")[0].contentWindow.OCA.Onlyoffice.editorInsertImage, + false, + imageMimes, + true + ); + }; + + OCA.Onlyoffice.onRequestMailMergeRecipients = function (recipientMimes) { + OC.dialogs.filepicker( + t(OCA.Onlyoffice.AppName, "Select recipients"), + $("#onlyoffice-frame")[0].contentWindow.OCA.Onlyoffice.editorSetRecipient, + false, + recipientMimes, + true + ); + }; + + OCA.Onlyoffice.onRequestSelectDocument = function ( + revisedMimes, + documentSelectionType + ) { + let title; + switch (documentSelectionType) { + case "combine": + title = t(OCA.Onlyoffice.AppName, "Select file to combine"); + break; + default: + title = t(OCA.Onlyoffice.AppName, "Select file to compare"); + } + OC.dialogs.filepicker( + title, + $( + "#onlyoffice-frame" + )[0].contentWindow.OCA.Onlyoffice.editorSetRequested.bind({ + documentSelectionType, + }), + false, + revisedMimes, + true + ); + }; + + OCA.Onlyoffice.onRequestReferenceSource = function (referenceSourceMimes) { + OC.dialogs.filepicker( + t(OCA.Onlyoffice.AppName, "Select data source"), + $("#onlyoffice-frame")[0].contentWindow.OCA.Onlyoffice + .editorReferenceSource, + false, + referenceSourceMimes, + true + ); + }; + + OCA.Onlyoffice.onDocumentReady = function (documentType) { + if ( + documentType === "word" || + documentType === "cell" || + documentType === "slide" + ) { + OCA.Onlyoffice.bindVersionClick(); + } else { + OCA.Onlyoffice.unbindVersionClick(); } - OCA.Onlyoffice.onDocumentReady = function (documentType) { - if (documentType === "word" - || documentType === "cell" - || documentType === "slide") { - OCA.Onlyoffice.bindVersionClick(); - } else { - OCA.Onlyoffice.unbindVersionClick(); - } - - OCA.Onlyoffice.setViewport(); - }; - - OCA.Onlyoffice.changeFavicon = function (favicon) { - $('link[rel="icon"]').attr("href", favicon); - }; - - OCA.Onlyoffice.setViewport = function() { - document.querySelector('meta[name="viewport"]').setAttribute("content","width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"); - }; - - OCA.Onlyoffice.onShowMessage = function (messageObj) { - OC.Notification.show(messageObj.message, messageObj.props); - }; - - OCA.Onlyoffice.onRequestEditRights = function () { - $("#onlyofficeFrame").attr("src", $("#onlyofficeFrame").attr("src") + "&forceEdit=true"); - }; - - window.addEventListener("message", function (event) { - if ($("#onlyofficeFrame")[0]) { - if ($("#onlyofficeFrame")[0].contentWindow !== event.source - || !event.data["method"]) { - return; - } - } - switch (event.data.method) { - case "editorRequestClose": - OCA.Onlyoffice.onRequestClose(); - break; - case "editorRequestSharingSettings": - if (OCA.Onlyoffice.OpenShareDialog) { - OCA.Onlyoffice.OpenShareDialog(); - } - break; - case "onRefreshVersionsDialog": - if (OCA.Onlyoffice.RefreshVersionsDialog) { - OCA.Onlyoffice.RefreshVersionsDialog(); - } - break; - case "editorRequestSaveAs": - OCA.Onlyoffice.onRequestSaveAs(event.data.param); - break; - case "editorRequestInsertImage": - OCA.Onlyoffice.onRequestInsertImage(event.data.param); - break; - case "editorRequestMailMergeRecipients": - OCA.Onlyoffice.onRequestMailMergeRecipients(event.data.param); - break; - case "editorRequestSelectDocument": - OCA.Onlyoffice.onRequestSelectDocument(event.data.param, event.data.documentSelectionType); - break; - case "editorRequestReferenceSource": - OCA.Onlyoffice.onRequestReferenceSource(event.data.param); - break; - case "onDocumentReady": - OCA.Onlyoffice.onDocumentReady(event.data.param); - break; - case "changeFavicon": - OCA.Onlyoffice.changeFavicon(event.data.param); - break; - case "onShowMessage": - OCA.Onlyoffice.onShowMessage(event.data.param); - break; - case "onRequestEditRights": - OCA.Onlyoffice.onRequestEditRights(); - } - }, false); - - window.addEventListener("popstate", function (event) { - if ($("#onlyofficeFrame").length - && location.href.indexOf(OCA.Onlyoffice.AppName) == -1) { - OCA.Onlyoffice.onRequestClose(); - } - }); - - window.addEventListener("DOMNodeRemoved", function(event) { - if ($(event.target).length && $("#onlyofficeFrame").length - && ($(event.target)[0].id === "viewer" || $(event.target)[0].id === $("#onlyofficeFrame")[0].id)) { - OCA.Onlyoffice.changeFavicon($("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.faviconBase); - window.document.title = $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.titleBase; + OCA.Onlyoffice.setViewport(); + }; + + OCA.Onlyoffice.changeFavicon = function (favicon) { + $('link[rel="icon"]').attr("href", favicon); + }; + + OCA.Onlyoffice.setViewport = function () { + document + .querySelector('meta[name="viewport"]') + .setAttribute( + "content", + "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" + ); + }; + + OCA.Onlyoffice.onShowMessage = function (messageObj) { + OC.Notification.show(messageObj.message, messageObj.props); + }; + + window.addEventListener( + "message", + function (event) { + if ($("#onlyoffice-frame")[0]) { + if ( + $("#onlyoffice-frame")[0].contentWindow !== event.source || + !event.data["method"] + ) { + return; } - }); - + } + switch (event.data.method) { + case "editorRequestClose": + OCA.Onlyoffice.onRequestClose(); + break; + case "editorRequestSharingSettings": + if (OCA.Onlyoffice.OpenShareDialog) { + OCA.Onlyoffice.OpenShareDialog(); + } + break; + case "onRefreshVersionsDialog": + if (OCA.Onlyoffice.RefreshVersionsDialog) { + OCA.Onlyoffice.RefreshVersionsDialog(); + } + break; + case "editorRequestSaveAs": + OCA.Onlyoffice.onRequestSaveAs(event.data.param); + break; + case "editorRequestInsertImage": + OCA.Onlyoffice.onRequestInsertImage(event.data.param); + break; + case "editorRequestMailMergeRecipients": + OCA.Onlyoffice.onRequestMailMergeRecipients(event.data.param); + break; + case "editorRequestSelectDocument": + OCA.Onlyoffice.onRequestSelectDocument( + event.data.param, + event.data.documentSelectionType + ); + break; + case "editorRequestReferenceSource": + OCA.Onlyoffice.onRequestReferenceSource(event.data.param); + break; + case "onDocumentReady": + OCA.Onlyoffice.onDocumentReady(event.data.param); + break; + case "changeFavicon": + OCA.Onlyoffice.changeFavicon(event.data.param); + break; + case "onShowMessage": + OCA.Onlyoffice.onShowMessage(event.data.param); + break; + } + }, + false + ); + + window.addEventListener("popstate", function (event) { + if ( + $("#onlyoffice-frame").length && + location.href.indexOf(OCA.Onlyoffice.AppName) === -1 + ) { + OCA.Onlyoffice.onRequestClose(); + } + }); + + window.addEventListener("DOMNodeRemoved", function (event) { + if ( + $(event.target).length && + $("#onlyoffice-frame").length && + ($(event.target)[0].id === "viewer" || + $(event.target)[0].id === $("#onlyoffice-frame")[0].id) + ) { + OCA.Onlyoffice.changeFavicon( + $("#onlyoffice-frame")[0].contentWindow.OCA.Onlyoffice.faviconBase + ); + window.document.title = + $("#onlyoffice-frame")[0].contentWindow.OCA.Onlyoffice.titleBase; + } + }); })(OCA); diff --git a/js/main.js b/js/main.js index c6a4921c..a174641c 100644 --- a/js/main.js +++ b/js/main.js @@ -17,554 +17,686 @@ */ (function (OCA) { + OCA.Onlyoffice = _.extend( + { + AppName: "onlyoffice", + context: null, + folderUrl: null, + }, + OCA.Onlyoffice + ); + + OCA.Onlyoffice.setting = {}; + OCA.Onlyoffice.mobile = + /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini|Macintosh/i.test( + navigator.userAgent + ) && + navigator.maxTouchPoints && + navigator.maxTouchPoints > 1; + + OCA.Onlyoffice.CreateFile = function ( + name, + fileList, + templateId, + targetPath, + open = true + ) { + const dir = fileList.getCurrentDirectory(); + let winEditor = null; + if ( + (!OCA.Onlyoffice.setting.sameTab || + OCA.Onlyoffice.mobile || + OCA.Onlyoffice.Desktop) && + open + ) { + $loaderUrl = OCA.Onlyoffice.Desktop + ? "" + : OC.filePath(OCA.Onlyoffice.AppName, "templates", "loader.html"); + winEditor = window.open($loaderUrl); + } - OCA.Onlyoffice = _.extend({ - AppName: "onlyoffice", - context: null, - folderUrl: null, - }, OCA.Onlyoffice); - - OCA.Onlyoffice.setting = {}; - OCA.Onlyoffice.mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini|Macintosh/i.test(navigator.userAgent) - && navigator.maxTouchPoints && navigator.maxTouchPoints > 1; - - OCA.Onlyoffice.CreateFile = function (name, fileList, templateId, targetPath, open = true) { - var dir = fileList.getCurrentDirectory(); - - if ((!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.mobile || OCA.Onlyoffice.Desktop) && open) { - $loaderUrl = OCA.Onlyoffice.Desktop ? "" : OC.filePath(OCA.Onlyoffice.AppName, "templates", "loader.html"); - var winEditor = window.open($loaderUrl); - } - - var createData = { - name: name, - dir: dir - }; - - if (templateId) { - createData.templateId = templateId; - } + const createData = { + name, + dir, + }; - if (targetPath) { - createData.targetPath = targetPath; - } + if (templateId) { + createData.templateId = templateId; + } - if ($("#isPublic").val()) { - createData.shareToken = encodeURIComponent($("#sharingToken").val()); - } + if (targetPath) { + createData.targetPath = targetPath; + } - $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/new"), - createData, - function onSuccess(response) { - if (response.error) { - if (winEditor) { - winEditor.close(); - } - OC.Notification.show(response.error, { - type: "error", - timeout: 3 - }); - return; - } - - fileList.add(response, { animate: true }); - if (open) { - let fileName = response.name; - let extension = OCA.Onlyoffice.GetFileExtension(fileName); - let forceEdit = OCA.Onlyoffice.setting.formats[extension].fillForms; - OCA.Onlyoffice.OpenEditor(response.id, dir, fileName, 0, winEditor, forceEdit); - } - - OCA.Onlyoffice.context = { fileList: fileList }; - OCA.Onlyoffice.context.fileName = response.name; - - OC.Notification.show(t(OCA.Onlyoffice.AppName, "File created"), { - timeout: 3 - }); - } - ); - }; + if ($("#isPublic").val()) { + createData.shareToken = encodeURIComponent($("#sharingToken").val()); + } - OCA.Onlyoffice.OpenEditor = function (fileId, fileDir, fileName, version, winEditor, forceEdit) { - var filePath = ""; - if (fileName) { - filePath = fileDir.replace(new RegExp("\/$"), "") + "/" + fileName; + $.post( + OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/new"), + createData, + function onSuccess(response) { + if (response.error) { + if (winEditor) { + winEditor.close(); + } + OC.Notification.show(response.error, { + type: "error", + timeout: 3, + }); + return; } - var url = OC.generateUrl("/apps/" + OCA.Onlyoffice.AppName + "/{fileId}?filePath={filePath}", - { - fileId: fileId, - filePath: filePath - }); - if ($("#isPublic").val()) { - url = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/{shareToken}?fileId={fileId}", - { - shareToken: encodeURIComponent($("#sharingToken").val()), - fileId: fileId - }); + fileList.add(response, { animate: true }); + if (open) { + const fileName = response.name; + const extension = OCA.Onlyoffice.GetFileExtension(fileName); + OCA.Onlyoffice.OpenEditor( + response.id, + dir, + fileName, + 0, + winEditor + ); } - if (forceEdit) { - url += "&forceEdit=true"; - } + OCA.Onlyoffice.context = { fileList }; + OCA.Onlyoffice.context.fileName = response.name; - if (version > 0) { - url += "&version=" + version; + OC.Notification.show(t(OCA.Onlyoffice.AppName, "File created"), { + timeout: 3, + }); + } + ); + }; + + OCA.Onlyoffice.OpenEditor = function ( + fileId, + fileDir, + fileName, + version, + winEditor + ) { + let filePath = ""; + if (fileName) { + filePath = fileDir.replace(new RegExp("/$"), "") + "/" + fileName; + } + let url = OC.generateUrl( + "/apps/" + OCA.Onlyoffice.AppName + "/{fileId}?filePath={filePath}", + { + fileId, + filePath, + } + ); + + if ($("#isPublic").val()) { + url = OC.generateUrl( + "apps/" + OCA.Onlyoffice.AppName + "/s/{shareToken}?fileId={fileId}", + { + shareToken: encodeURIComponent($("#sharingToken").val()), + fileId, } + ); + } - if (winEditor && winEditor.location) { - winEditor.location.href = url; - } else if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.mobile || OCA.Onlyoffice.Desktop) { - winEditor = window.open(url, "_blank"); - } else if ($("#isPublic").val() === "1" && $("#mimetype").val() !== "httpd/unix-directory") { - location.href = url; - } else { - var $iframe = $("