DEV: Teardown leaky page:changed `appEvent`s between tests

This commit is contained in:
David Taylor 2021-10-27 16:25:00 +01:00
parent d2ddb82022
commit 0bec323204
1 changed files with 14 additions and 8 deletions

View File

@ -6,15 +6,21 @@ export default {
initialize(container) {
// workaround for Safari on iOS 14.3
// seems it has started using opengraph tags when sharing
let appEvents = container.lookup("service:app-events");
const ogTitle = document.querySelector("meta[property='og:title']"),
ogUrl = document.querySelector("meta[property='og:url']");
this.appEvents = container.lookup("service:app-events");
this.ogTitle = document.querySelector("meta[property='og:title']");
this.ogUrl = document.querySelector("meta[property='og:url']");
if (ogTitle && ogUrl) {
appEvents.on("page:changed", (data) => {
ogTitle.setAttribute("content", data.title);
ogUrl.setAttribute("content", getAbsoluteURL(data.url));
});
if (this.ogTitle && this.ogUrl) {
this.appEvents.on("page:changed", this, this.updateOgAttributes);
}
},
updateOgAttributes(data) {
this.ogTitle.setAttribute("content", data.title);
this.ogUrl.setAttribute("content", getAbsoluteURL(data.url));
},
teardown() {
this.appEvents.off("page:changed", this, this.updateOgAttributes);
},
};