PageSourceSearch

https://nube.elcampello.es:3560/apps/onlyoffice/js/main.js?v=f9abac7e-17

js elcampello.es collected 2026-10-02 05:11:43 UTC 21,999 bytes, 573 lines download raw bytes

1/**
2 *
3 * (c) Copyright Ascensio System SIA 2021
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19(function (OCA) {
20
21    OCA.Onlyoffice = _.extend({
22            AppName: "onlyoffice",
23            context: null,
24            folderUrl: null,
25            frameSelector: null,
26        }, OCA.Onlyoffice);
27
28    OCA.Onlyoffice.setting = {};
29    OCA.Onlyoffice.mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini|Macintosh/i.test(navigator.userAgent)
30                            && navigator.maxTouchPoints && navigator.maxTouchPoints > 1;
31
32    OCA.Onlyoffice.CreateFile = function (name, fileList, templateId, targetId, open = true) {
33        var dir = fileList.getCurrentDirectory();
34
35        if ((!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.mobile || OCA.Onlyoffice.Desktop) && open) {
36            $loaderUrl = OCA.Onlyoffice.Desktop ? "" : OC.filePath(OCA.Onlyoffice.AppName, "templates", "loader.html");
37            var winEditor = window.open($loaderUrl);
38        }
39
40        var createData = {
41            name: name,
42            dir: dir
43        };
44
45        if (templateId) {
46            createData.templateId = templateId;
47        }
48
49        if (targetId) {
50            createData.targetId = targetId;
51        }
52
53        if ($("#isPublic").val()) {
54            createData.shareToken = encodeURIComponent($("#sharingToken").val());
55        }
56
57        $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/new"),
58            createData,
59            function onSuccess(response) {
60                if (response.error) {
61                    if (winEditor) {
62                        winEditor.close();
63                    }
64                    OCP.Toast.error(response.error);
65                    return;
66                }
67
68                fileList.add(response, { animate: true });
69                if (open) {
70                    OCA.Onlyoffice.OpenEditor(response.id, dir, response.name, 0, winEditor);
71
72                    OCA.Onlyoffice.context = { fileList: fileList };
73                    OCA.Onlyoffice.context.fileName = response.name;
74                    OCA.Onlyoffice.context.dir = dir;
75                }
76
77                OCP.Toast.success(t(OCA.Onlyoffice.AppName, "File created"));
78            }
79        );
80    };
81
82    OCA.Onlyoffice.OpenEditor = function (fileId, fileDir, fileName, version, winEditor) {
83        var filePath = "";
84        if (fileName) {
85            filePath = fileDir.replace(new RegExp("\/$"), "") + "/" + fileName;
86        }
87        var url = OC.generateUrl("/apps/" + OCA.Onlyoffice.AppName + "/{fileId}?filePath={filePath}",
88            {
89                fileId: fileId,
90                filePath: filePath
91            });
92
93        if ($("#isPublic").val()) {
94            url = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/{shareToken}?fileId={fileId}",
95                {
96                    shareToken: encodeURIComponent($("#sharingToken").val()),
97                    fileId: fileId
98                });
99        }
100
101        if (version > 0) {
102            url += "&version=" + version;
103        }
104
105        if (winEditor && winEditor.location) {
106            winEditor.location.href = url;
107        } else if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.mobile || OCA.Onlyoffice.Desktop) {
108            winEditor = window.open(url, "_blank");
109        } else if ($("#isPublic").val() === "1" && !$("#filestable").length) {
110            location.href = url;
111        } else {
112            OCA.Onlyoffice.frameSelector = "#onlyofficeFrame";
113            var $iframe = $("<iframe id=\"onlyofficeFrame\" nonce=\"" + btoa(OC.requestToken) + "\" scrolling=\"no\" allowfullscreen src=\"" + url + "&inframe=true\" />");
114            $("#app-content").append($iframe);
115
116            $("body").addClass("onlyoffice-inline");
117
118            if (OCA.Files.Sidebar) {
119                OCA.Files.Sidebar.close();
120            }
121
122            var scrollTop = $(window).scrollTop();
123            $(OCA.Onlyoffice.frameSelector).css("top", scrollTop);
124
125            OCA.Onlyoffice.folderUrl = location.href;
126            window.history.pushState(null, null, url);
127        }
128    };
129
130    OCA.Onlyoffice.CloseEditor = function () {
131        OCA.Onlyoffice.frameSelector = null;
132
133        $("body").removeClass("onlyoffice-inline");
134
135        OCA.Onlyoffice.context = null;
136
137        var url = OCA.Onlyoffice.folderUrl;
138        if (!!url) {
139            window.history.pushState(null, null, url);
140            OCA.Onlyoffice.folderUrl = null;
141        }
142
143        OCA.Onlyoffice.bindVersionClick();
144    };
145
146    OCA.Onlyoffice.OpenShareDialog = function () {
147        if (OCA.Onlyoffice.context) {
148            if (!$("#app-sidebar-vue").is(":visible")) {
149                OCA.Files.Sidebar.open(OCA.Onlyoffice.context.dir + "/" + OCA.Onlyoffice.context.fileName);
150                OCA.Files.Sidebar.setActiveTab("sharing");
151            } else {
152                OCA.Files.Sidebar.close();
153            }
154        }
155    };
156
157    OCA.Onlyoffice.RefreshVersionsDialog = function () {
158        if (OCA.Onlyoffice.context) {
159            if ($("#app-sidebar-vue").is(":visible")) {
160                OCA.Files.Sidebar.close();
161                OCA.Files.Sidebar.open(OCA.Onlyoffice.context.dir + "/" + OCA.Onlyoffice.context.fileName);
162                OCA.Files.Sidebar.setActiveTab("versionsTabView");
163            }
164        }
165    };
166
167    OCA.Onlyoffice.FileClick = function (fileName, context) {
168        var fileInfoModel = context.fileInfoModel || context.fileList.getModelForFile
168(fileName);
169        OCA.Onlyoffice.OpenEditor(fileInfoModel.id, context.dir, fileName);
170
171        OCA.Onlyoffice.context = context;
172        OCA.Onlyoffice.context.fileName = fileName;
173    };
174
175    OCA.Onlyoffice.FileConvertClick = function (fileName, context) {
176        var fileInfoModel = context.fileInfoModel || context.fileList.getModelForFile(fileName);
177        var fileList = context.fileList;
178
179        var convertData = {
180            fileId: fileInfoModel.id
181        };
182
183        if ($("#isPublic").val()) {
184            convertData.shareToken = encodeURIComponent($("#sharingToken").val());
185        }
186
187        $.post(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/convert"),
188            convertData,
189            function onSuccess(response) {
190                if (response.error) {
191                    OCP.Toast.error(response.error);
192                    return;
193                }
194
195                if (response.parentId == fileList.dirInfo.id) {
196                    fileList.add(response, { animate: true });
197                }
198
199                OCP.Toast.success(t(OCA.Onlyoffice.AppName, "File has been converted. Its content might look different."));
200            });
201    };
202
203    OCA.Onlyoffice.DownloadClick = function (fileName, context) {
204        $.get(OC.filePath(OCA.Onlyoffice.AppName, "templates", "downloadPicker.html"), 
205            function (tmpl) {
206                var dialog = $(tmpl).octemplate({
207                    dialog_name: "download-picker",
208                    dialog_title: t("onlyoffice", "Download as")
209                });
210
211                $(dialog[0].querySelectorAll("p")).text(t(OCA.Onlyoffice.AppName, "Choose a format to convert {fileName}", {fileName: fileName}));
212
213                var extension = getFileExtension(fileName);
214                var selectNode = dialog[0].querySelectorAll("select")[0];
215                var optionNodeOrigin = selectNode.querySelectorAll("option")[0];
216
217                $(optionNodeOrigin).attr("data-value", extension);
218                $(optionNodeOrigin).text(t(OCA.Onlyoffice.AppName, "Origin format"));
219
220                dialog[0].dataset.format = extension;
221                selectNode.onclick = function() {
222                    dialog[0].dataset.format = $("#onlyoffice-download-select option:selected").attr("data-value");
223                }
224
225                OCA.Onlyoffice.setting.formats[extension].saveas.forEach(ext => {
226                    var optionNode = optionNodeOrigin.cloneNode(true);
227
228                    $(optionNode).attr("data-value", ext);
229                    $(optionNode).text(ext);
230
231                    selectNode.append(optionNode);
232                })
233
234                $("body").append(dialog)
235
236                $("#download-picker").ocdialog({
237                    closeOnEscape: true,
238                    modal: true,
239                    buttons: [{
240                        text: t("core", "Cancel"),
241                        classes: "cancel",
242                        click: function() {
243                            $(this).ocdialog("close")
244                        }
245                    }, {
246                        text: t("onlyoffice", "Download"),
247                        classes: "primary",
248                        click: function() {
249                            var format = this.dataset.format;
250                            var fileId = context.fileInfoModel.id;
251                            var downloadLink = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/downloadas?fileId={fileId}&toExtension={toExtension}",{
252                                fileId: fileId,
253                                toExtension: format
254                            });
255
256                            location.href = downloadLink;
257                            $(this).ocdialog("close")
258                        }
259                    }]
260                });
261            });
262    };
263
264    OCA.Onlyoffice.OpenFormPicker = function (name, filelist) {
265        var filterMimes = [
266            "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
267        ];
268
269        var buttons = [
270            {
271                text: t(OCA.Onlyoffice.AppName, "Blank"),
272                type: "blank"
273            },
274            {
275                text: t(OCA.Onlyoffice.AppName, "From text document"),
276                type: "target",
277                defaultButton: true
278            }
279        ];
280
281        OC.dialogs.filepicker(t(OCA.Onlyoffice.AppName, "Create new Form template"),
282            function (filePath, type) {
283                var dialogFileList = OC.dialogs.filelist;
284                var targetId = 0;
285
286                if (type === "target") {
287                    var targetFileName = filePath.split("/").pop();
288                    dialogFileList.forEach(item => {
289                        if (item.name === targetFileName) {
290                            targetId = item.id;
291                        }
292                    })
293                }
294
295                OCA.Onlyoffice.CreateFile(name, filelist, 0, targetId);
296            },
297            false,
298            filterMimes,
299            true,
300            OC.dialogs.FILEPICKER_TYPE_CUSTOM,
301            filelist.getCurrentDirectory(),
302            {
303                buttons: buttons
304            });
305    };
306
307    OCA.Onlyoffice.CreateFormClick = function (fileName, context) {
308        var fileList = context.fileList;
309        var name = fileName.replace(/\.[^.]+$/, ".oform");
310        var targetId = context.fileInfoModel.id;
311
312        OCA.Onlyoffice.CreateFile(name, fileList, 0, targetId, false);
313    };
314
315    OCA.Onlyoffice.GetSettings = function (callbackSettings) {
316        if (OCA.Onlyoffice.setting.formats) {
317
318            callbackSettings();
319
320        } else {
321
322            $.get(OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/ajax/settings"),
323                function onSuccess(settings) {
324                    OCA.Onlyoffice.setting = settings;
325
326                    callbackSettings();
327                }
328            );
329
330        }
331    };
332
333    OCA.Onlyoffice.registerAction = function() {
334        var register = function () {
335            var formats = OCA.Onlyoffice.setting.formats;
336
337            $.each(formats, function (ext, config) {
338                if (!config.mime) {
339                    return true;
340                }
341                OCA.Files.fileActions.registerAction({
342                    name: "onlyofficeOpen",
343                    displayName: t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE"),
344                    mime: config.mime,
345                    permissions: OC.PERMISSION_READ,
346                    iconClass: "icon-onlyoffice-open",
347                    actionHandler: OCA.Onlyoffice.FileClick
348                });
349
350                if (config.def) {
351                    OCA.Files.fileActions.setDefault(config.mime, "onlyofficeOpen");
352                }
353
354                if (config.conv) {
355                    OCA.Files.fileActions.registerAction({
356                        name: "onlyofficeConvert",
357                        displayName: t(OCA.Onlyoffice.AppName, "Convert with ONLYOFFICE"),
358                        mime: config.mime,
359                        permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ),
360                        iconClass: "icon-onlyoffice-convert",
361                        actionHandler: OCA.Onlyoffice.FileConvertClick
362                    });
363                }
364
365                if (config.fillForms) {
366                    OCA.Files.fileActions.registerAction({
367                        name: "onlyofficeFill",
368                        displayName: t(OCA.Onlyoffice.AppName, "Fill in form in ONLYOFFICE"),
369                        mime: config.mime,
370                        permissions: OC.PERMISSION_UPDATE,
371                        iconClass: "icon-onlyoffice-fill",
372                        actionHandler: OCA.Onlyoffice.FileClick
373                    });
374                }
375
376                if (config.createForm) {
377                    OCA.Files.fileActions.registerAction({
378                        name: "onlyofficeCreateForm",
379                        displayName: t(OCA.Onlyoffice.AppName, "Create form"),
380                        mime: config.mime,
381                        permissions: ($("#isPublic").val() ? OC.PERMISSION_UPDATE : OC.PERMISSION_READ),
382                        iconClass: "icon-onlyoffice-create",
383                        actionHandler: OCA.Onlyoffice.CreateFormClick
384                    });
385                }
386
387                if (config.saveas && !$("#isPublic").val()) {
388                    OCA.Files.fileActions.registerAction({
389                        name: "onlyofficeDownload",
390                        displayName: t(OCA.Onlyoffice.AppName, "Download as"),
391                        mime: config.mime,
392                        permissions: OC.PERMISSION_READ,
393                        iconClass: "icon-onlyoffice-download",
394                        actionHandler: OCA.Onlyoffice.DownloadClick
395                    });
396                }
397            });
398        }
399
400        OCA.Onlyoffice.GetSettings(register);
401    };
402
403    OCA.Onlyoffice.NewFileMenu = {
404        attach: function (menu) {
405            var fileList = menu.fileList;
406
407            if (fileList.id !== "files" && fileList.id !== "files.public") {
408                return;
409            }
410
411            if ($("#isPublic").val() === "1" && !!$("#filestable").length
412                || OC.config.version.split(".")[0] < 21) {
413                menu.addMenuEntry({
414                    id: "onlyofficeDocx",
415                    displayName: t(OCA.Onlyoffice.AppName, "Document"),
416                    templateName: t(OCA.Onlyoffice.AppName, "Document"),
417                    iconClass: "icon-onlyoffice-new-docx",
418                    fileType: "docx",
419                    actionHandler: function (name) {
420                        if (!$("#isPublic").val() && OCA.Onlyoffice.TemplateExist("document")) {
421                            OCA.Onlyoffice.OpenTemplatePicker(name, ".docx", "document");
422                        } else {
423                            OCA.Onlyoffice.CreateFile(name + ".docx", fileList);
424                        }
425                    }
426                });
427
428                menu.addMenuEntry({
429                    id: "onlyofficeXlsx",
430                    displayName: t(OCA.Onlyoffice.AppName, "Spreadsheet"),
431                    templateName: t(OCA.Onlyoffice.AppName, "Spreadsheet"),
432                    iconClass: "icon-onlyoffice-new-xlsx",
433                    fileType: "xlsx",
434                    actionHandler: function (name) {
435                        if (!$("#isPublic").val() && OCA.Onlyoffice.TemplateExist("spreadsheet")) {
436                            OCA.Onlyoffice.OpenTemplatePicker(name, ".xlsx", "spreadsheet");
437                        } else {
438                            OCA.Onlyoffice.CreateFile(name + ".xlsx", fileList);
439                        }
440                    }
441                });
442
443                menu.addMenuEntry({
444                    id: "onlyofficePpts",
445                    displayName: t(OCA.Onlyoffice.AppName, "Presentation"),
446                    templateName: t(OCA.Onlyoffice.AppName, "Presentation"),
447                    iconClass: "icon-onlyoffice-new-pptx",
448                    fileType: "pptx",
449                    actionHandler: function (name) {
450                        if (!$("#isPublic").val() && OCA.Onlyoffice.TemplateExist("presentation")) {
451                            OCA.Onlyoffice.OpenTemplatePicker(name, ".pptx", "presentation");
452                        } else {
453                            OCA.Onlyoffice.CreateFile(name + ".pptx", fileList);
454                        }
455                    }
456                });
457
458                if (OCA.Onlyoffice.GetTemplates) {
459                    OCA.Onlyoffice.GetTemplates();
460                }
461            }
462
463            menu.addMenuEntry({
464                id: "onlyofficeDocxf",
465                displayName: t(OCA.Onlyoffice.AppName, "Form template"),
466                templateName: t(OCA.Onlyoffice.AppName, "Form template"),
467                iconClass: "icon-onlyoffice-new-docxf",
468                fileType: "docxf",
469                actionHandler: function (name) {
470                    OCA.Onlyoffice.OpenFormPicker(name + ".docxf", fileList);
471                }
472            });
473        }
474    };
475
476    var getFileExtension = function (fileName) {
477        var extension = fileName.substr(fileName.lastIndexOf(".") + 1).toLowerCase();
478        return extension;
479    }
480
481    OCA.Onlyoffice.openVersion = function (fileId, version) {
482        if (OCA.Onlyoffice.frameSelector) {
483            $(OCA.Onlyoffice.frameSelector)[0].contentWindow.OCA.Onlyoffice.onRequestHistory(version);
484            return;
485        }
486
487        OCA.Onlyoffice.OpenEditor(fileId, "", "", version)
488    };
489
490    OCA.Onlyoffice.bindVersionClick = function () {
491        OCA.Onlyoffice.unbindVersionClick();
492        $(document).on("click.onlyoffice-version", "#versionsTabView .downloadVersion", function() {
493            var ext = $(this).attr("download").split(".").pop();
494            if (!OCA.Onlyoffice.setting.formats[ext]
495                || !OCA.Onlyoffice.setting.formats[ext].def) {
496                return true;
497            }
498
499            var versionNodes = $("#versionsTabView ul.versions>li");
500            var versionNode = $(this).closest("#versionsTabView ul.versions>li")[0];
501
502            var href = $(this).attr("href");
503            var search = new RegExp("\/versions\/(\\d+)\/\\d+$");
504            var result = search.exec(href);
505            if (result && result.length > 1) {
506                var fileId = result[1];
507            }
508            if (!fileId) {
509                return true;
510            }
511
512            var versionNum = versionNodes.length - $.inArray(versionNode, versionNodes);
513
514            OCA.Onlyoffice.openVersion(fileId, versionNum);
515
516            return false;
517        });
518    };
519
520    OCA.Onlyoffice.unbindVersionClick = function() {
521        $(document).off("click.onlyoffice-version", "#versionsTabView .downloadVersion");
522    }
523
524    var initPage = function () {
525        if ($("#isPublic").val() === "1" && !$("#filestable").length) {
526            //file by shared link
527            var fileName = $("#filename").val();
528            var extension = getFileExtension(fileName);
529
530            var initSharedButton = function () {
531                var formats = OCA.Onlyoffice.setting.formats;
532
533                var config = formats[extension];
534                if (!config) {
535                    return;
536                }
537
538                var editorUrl = OC.generateUrl("apps/" + OCA.Onlyoffice.AppName + "/s/" + encodeURIComponent($("#sharingToken").val()));
539
540                if (_oc_appswebroots.richdocuments
541                    || _oc_appswebroots.files_pdfviewer && extension === "pdf"
542                    || _oc_appswebroots.text && extension === "txt") {
543
544                    var button = document.createElement("a");
545                    button.href = editorUrl;
546                    button.className = "onlyoffice-public-open button";
547                    button.innerText = t(OCA.Onlyoffice.AppName, "Open in ONLYOFFICE")
548
549                    if (!OCA.Onlyoffice.setting.sameTab) {
550                        button.target = "_blank";
551                    }
552
553                    $("#preview").prepend(button);
554                } else {
555                    OCA.Onlyoffice.frameSelector = "#onlyofficeFrame";
556                    var $iframe = $("<iframe id=\"onlyofficeFrame\" nonce=\"" + btoa(OC.requestToken) + "\" scrolling=\"no\" allowfullscreen src=\"" + editorUrl + "?inframe=true\" />");
557                    $("#app-content").append($iframe);
558                }
559            };
560
561            OCA.Onlyoffice.GetSettings(initSharedButton);
562        } else {
563            OC.Plugins.register("OCA.Files.NewFileMenu", OCA.Onlyoffice.NewFileMenu);
564
565            OCA.Onlyoffice.registerAction();
566
567            OCA.Onlyoffice.bindVersionClick();
568        }
569    };
570
571    initPage();
572
573})(OCA);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.