diff options
author | Sergey Linnik <sergey.linnik@onlyoffice.com> | 2020-06-11 14:35:56 +0300 |
---|---|---|
committer | Sergey Linnik <sergey.linnik@onlyoffice.com> | 2020-06-11 14:36:30 +0300 |
commit | bf877472038bf8d3763fb5b0eba62a7e7891ba89 (patch) | |
tree | d1cdddfe7276fcebfc9ca85d0d3448b6632c92fe | |
parent | 075cb75b9c7ecf78fbd944bf8e62c6aad63b954d (diff) |
listener in a separate script
-rw-r--r-- | appinfo/application.php | 10 | ||||
-rw-r--r-- | js/listener.js | 147 | ||||
-rw-r--r-- | js/main.js | 103 |
3 files changed, 159 insertions, 101 deletions
diff --git a/appinfo/application.php b/appinfo/application.php index fe897d7..f35aff6 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -73,6 +73,11 @@ class Application extends App { && $this->appConfig->isUserAllowedToUse()) { Util::addScript("onlyoffice", "desktop"); Util::addScript("onlyoffice", "main"); + + if ($this->appConfig->GetSameTab()) { + Util::addScript("onlyoffice", "listener"); + } + Util::addStyle("onlyoffice", "main"); } }); @@ -82,6 +87,11 @@ class Application extends App { if (!empty($this->appConfig->GetDocumentServerUrl()) && $this->appConfig->SettingsAreSuccessful()) { Util::addScript("onlyoffice", "main"); + + if ($this->appConfig->GetSameTab()) { + Util::addScript("onlyoffice", "listener"); + } + Util::addStyle("onlyoffice", "main"); } }); diff --git a/js/listener.js b/js/listener.js new file mode 100644 index 0000000..44de53b --- /dev/null +++ b/js/listener.js @@ -0,0 +1,147 @@ +/** + * + * (c) Copyright Ascensio System SIA 2020 + * + * This program is a free software product. + * You can redistribute it and/or modify it under the terms of the GNU Affero General Public License + * (AGPL) version 3 as published by the Free Software Foundation. + * In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * For details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions of the Program + * must display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product logo when distributing the program. + * Pursuant to Section 7(e) we decline to grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as well as technical + * writing content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International. + * See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +(function (OCA) { + + OCA.Onlyoffice = _.extend({ + AppName: "onlyoffice", + context: null, + folderUrl: null, + }, OCA.Onlyoffice); + + OCA.Onlyoffice.ShowHeaderButton = function () { + var wrapper = $("<div id='onlyofficeHeader' />") + + var btnClose = $("<a class='icon icon-close-white'></a>"); + btnClose.on("click", function() { + OCA.Onlyoffice.CloseEditor(); + }); + wrapper.prepend(btnClose); + + if (!$("#isPublic").val()) { + var btnShare = $("<a class='icon icon-shared icon-white'></a>"); + btnShare.on("click", function () { + OCA.Onlyoffice.OpenShareDialog(); + }) + wrapper.prepend(btnShare); + } + + if (!$("#header .header-right").length) { + $("#header").append("<div class='header-right'></div>"); + } + wrapper.prependTo(".header-right"); + }; + + OCA.Onlyoffice.CloseEditor = function () { + $("body").removeClass("onlyoffice-inline"); + + $("#onlyofficeFrame").remove(); + $("#onlyofficeHeader").remove(); + + OCA.Onlyoffice.context = null; + + var url = OCA.Onlyoffice.folderUrl; + if (!!url) { + window.history.pushState(null, null, url); + OCA.Onlyoffice.folderUrl = null; + } + }; + + OCA.Onlyoffice.OpenShareDialog = function () { + if (OCA.Onlyoffice.context) { + if (!$("#app-sidebar").is(":visible")) { + OCA.Onlyoffice.context.fileList.showDetailsView(OCA.Onlyoffice.context.fileName, "shareTabView"); + OC.Apps.showAppSidebar(); + } else { + OC.Apps.hideAppSidebar(); + } + } + }; + + 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"); + }; + + OCA.Onlyoffice.onRequestInsertImage = function (imageMimes) { + OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Insert image"), + $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorInsertImage, + false, + imageMimes); + }; + + OCA.Onlyoffice.onRequestMailMergeRecipients = function (recipientMimes) { + OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select recipients"), + $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSetRecipient, + false, + recipientMimes); + }; + + OCA.Onlyoffice.onRequestCompareFile = function (revisedMimes) { + OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select file to compare"), + $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSetRevised, + false, + revisedMimes); + }; + + window.addEventListener("message", function(event) { + if ($("#onlyofficeFrame")[0].contentWindow !== event.source + || !event.data["method"]) { + return; + } + switch (event.data.method) { + case "editorShowHeaderButton": + OCA.Onlyoffice.ShowHeaderButton(); + break; + case "editorRequestClose": + OCA.Onlyoffice.CloseEditor(); + break; + case "editorRequestSharingSettings": + OCA.Onlyoffice.OpenShareDialog(); + 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 "editorRequestCompareFile": + OCA.Onlyoffice.onRequestCompareFile(event.data.param); + break; + } + }, false); + +})(OCA); @@ -31,7 +31,7 @@ OCA.Onlyoffice = _.extend({ AppName: "onlyoffice", context: null, - folderUrl: null + folderUrl: null, }, OCA.Onlyoffice); OCA.Onlyoffice.setting = {}; @@ -114,44 +114,6 @@ } }; - OCA.Onlyoffice.ShowHeaderButton = function () { - var wrapper = $("<div id='onlyofficeHeader' />") - - var btnClose = $("<a class='icon icon-close-white'></a>"); - btnClose.on("click", function() { - OCA.Onlyoffice.CloseEditor(); - }); - wrapper.prepend(btnClose); - - if (!$("#isPublic").val()) { - var btnShare = $("<a class='icon icon-shared icon-white'></a>"); - btnShare.on("click", function () { - OCA.Onlyoffice.OpenShareDialog(); - }) - wrapper.prepend(btnShare); - } - - if (!$("#header .header-right").length) { - $("#header").append("<div class='header-right'></div>"); - } - wrapper.prependTo(".header-right"); - }; - - OCA.Onlyoffice.CloseEditor = function () { - $("body").removeClass("onlyoffice-inline"); - - $("#onlyofficeFrame").remove(); - $("#onlyofficeHeader").remove(); - - OCA.Onlyoffice.context = null; - - var url = OCA.Onlyoffice.folderUrl; - if (!!url) { - window.history.pushState(null, null, url); - OCA.Onlyoffice.folderUrl = null; - } - }; - OCA.Onlyoffice.OpenShareDialog = function () { if (OCA.Onlyoffice.context) { if (!$("#app-sidebar").is(":visible")) { @@ -217,37 +179,6 @@ } }; - 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"); - }; - - OCA.Onlyoffice.onRequestInsertImage = function (imageMimes) { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Insert image"), - $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorInsertImage, - false, - imageMimes); - }; - - OCA.Onlyoffice.onRequestMailMergeRecipients = function (recipientMimes) { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select recipients"), - $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSetRecipient, - false, - recipientMimes); - }; - - OCA.Onlyoffice.onRequestCompareFile = function (revisedMimes) { - OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Select file to compare"), - $("#onlyofficeFrame")[0].contentWindow.OCA.Onlyoffice.editorSetRevised, - false, - revisedMimes); - }; - OCA.Onlyoffice.FileList = { attach: function (fileList) { if (fileList.id == "trashbin") { @@ -371,36 +302,6 @@ } }; - window.addEventListener("message", function(event) { - if ($("#onlyofficeFrame")[0].contentWindow !== event.source - || !event.data["method"]) { - return; - } - switch (event.data.method) { - case "editorRequestClose": - OCA.Onlyoffice.CloseEditor(); - break; - case "editorRequestSharingSettings": - OCA.Onlyoffice.OpenShareDialog(); - 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 "editorRequestCompareFile": - OCA.Onlyoffice.onRequestCompareFile(event.data.param); - break; - case "editorShowHeaderButton": - OCA.Onlyoffice.ShowHeaderButton(); - break; - } - }, false); - - $(document).ready(initPage) + $(document).ready(initPage); })(OCA); |