From f24146070f8fede2166a0e7741be7fb501ef059d Mon Sep 17 00:00:00 2001 From: Bryan Crotaz Date: Tue, 7 Nov 2017 02:42:47 +0000 Subject: [PATCH] stop opening click closing immediately --- addon/components/basic-dialog.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/addon/components/basic-dialog.js b/addon/components/basic-dialog.js index 1a595faf..73e3c493 100644 --- a/addon/components/basic-dialog.js +++ b/addon/components/basic-dialog.js @@ -81,22 +81,26 @@ export default Component.extend({ this.sendAction('onClose'); }; - const registerClick = () => $(document).on(`click.ember-modal-dialog-${guidFor(this)}`, handleClick); - - // setTimeout needed or else the click handler will catch the click that spawned this modal dialog - setTimeout(registerClick); - - if (this.get('isIOS')) { - const registerTouch = () => $(document).on(`touchend.ember-modal-dialog-${guidFor(this)}`, handleClick); - setTimeout(registerTouch); - } + // run next so that the opening click doesn't immediately close us + Ember.run.next(() => { + if (!this.get("isDestroying") && !this.get("isDestroyed")) { + const document = $(document); + const guid = guidFor(this); + document.on(`click.ember-modal-dialog-${guid}`, handleClick); + if (this.get('isIOS')) { + document.on(`touchend.ember-modal-dialog-${guid}`, handleClick); + } + } + }); this._super(...arguments); }, willDestroyElement() { - $(document).off(`click.ember-modal-dialog-${guidFor(this)}`); + const document = $(document); + const guid = guidFor(this); + document.off(`click.ember-modal-dialog-${guid}`); if (this.get('isIOS')) { - $(document).off(`touchend.ember-modal-dialog-${guidFor(this)}`); + document.off(`touchend.ember-modal-dialog-${guid}`); } this._super(...arguments); }