DEV: prevents share-popup to leak events (#7731)

This commit is contained in:
Joffrey JAFFEUX 2019-06-07 16:48:45 +02:00 committed by GitHub
parent da5255e560
commit 55325679ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,9 @@
import { wantsNewWindow } from "discourse/lib/intercept-click"; import { wantsNewWindow } from "discourse/lib/intercept-click";
import { longDateNoYear } from "discourse/lib/formatter"; import { longDateNoYear } from "discourse/lib/formatter";
import computed from "ember-addons/ember-computed-decorators"; import {
default as computed,
on
} from "ember-addons/ember-computed-decorators";
import Sharing from "discourse/lib/sharing"; import Sharing from "discourse/lib/sharing";
import { nativeShare } from "discourse/lib/pwa-utils"; import { nativeShare } from "discourse/lib/pwa-utils";
@ -148,19 +151,24 @@ export default Ember.Component.extend({
this._showUrl($target, url); this._showUrl($target, url);
}, },
@on("init")
_setupHandlers() {
this._boundMouseDownHandler = Ember.run.bind(this, this._mouseDownHandler);
this._boundClickHandler = Ember.run.bind(this, this._clickHandler);
this._boundKeydownHandler = Ember.run.bind(this, this._keydownHandler);
},
didInsertElement() { didInsertElement() {
this._super(...arguments); this._super(...arguments);
const $html = $("html"); $("html")
$html.on("mousedown.outside-share-link", this._mouseDownHandler.bind(this)); .on("mousedown.outside-share-link", this._boundMouseDownHandler)
.on(
$html.on(
"click.discourse-share-link", "click.discourse-share-link",
"button[data-share-url], .post-info .post-date[data-share-url]", "button[data-share-url], .post-info .post-date[data-share-url]",
this._clickHandler.bind(this) this._boundClickHandler
); )
.on("keydown.share-view", this._boundKeydownHandler);
$html.on("keydown.share-view", this._keydownHandler);
this.appEvents.on("share:url", this._shareUrlHandler); this.appEvents.on("share:url", this._shareUrlHandler);
}, },
@ -169,9 +177,9 @@ export default Ember.Component.extend({
this._super(...arguments); this._super(...arguments);
$("html") $("html")
.off("click.discourse-share-link", this._clickHandler) .off("click.discourse-share-link", this._boundClickHandler)
.off("mousedown.outside-share-link", this._mouseDownHandler) .off("mousedown.outside-share-link", this._boundMouseDownHandler)
.off("keydown.share-view", this._keydownHandler); .off("keydown.share-view", this._boundKeydownHandler);
this.appEvents.off("share:url", this._shareUrlHandler); this.appEvents.off("share:url", this._shareUrlHandler);
}, },