Skip to content

Commit

Permalink
Merge pull request 'fix: mutation observer instead of DOMNodeRemoved'…
Browse files Browse the repository at this point in the history
… from hotfix/mutation-observer into develop

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/onlyoffice-owncloud/pulls/9
  • Loading branch information
LinneyS committed Jan 14, 2025
2 parents 4a47ffe + ad206da commit 3874b5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 0 additions & 2 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
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) {
Expand Down
30 changes: 18 additions & 12 deletions js/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
OCA.Onlyoffice = _.extend(
{
AppName: "onlyoffice",
titleBase: window.document.title,
favIconBase: $('link[rel="icon"]').attr("href"),
},
OCA.Onlyoffice
);
Expand Down Expand Up @@ -198,18 +200,22 @@
}
});

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;
const mutationObserver = new MutationObserver(mutationRecords => {
if (mutationRecords[0] && mutationRecords[0].removedNodes) {
mutationRecords[0].removedNodes.forEach((node) => {
if (node.id && node.id === "onlyoffice-frame") {
OCA.Onlyoffice.changeFavicon(
OCA.Onlyoffice.favIconBase
);
window.document.title = OCA.Onlyoffice.titleBase;
}
})
}
});

mutationObserver.observe(document.documentElement, {
childList: true,
subtree: true,
characterDataOldValue: true,
});
})(OCA);

0 comments on commit 3874b5e

Please sign in to comment.