Skip to content

Commit

Permalink
Register unique clickOutSideToClose click handlers
Browse files Browse the repository at this point in the history
Prevents removal of the wrong listener when multiple dialogs are on the same page.
  • Loading branch information
oscarni committed Oct 21, 2016
1 parent ccf27b3 commit 64be133
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions addon/components/modal-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ember from 'ember';
import layout from '../templates/components/modal-dialog';

const { dasherize } = Ember.String;
const { $, computed, inject } = Ember;
const { $, computed, guidFor, inject } = Ember;
const { oneWay } = computed;
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
const computedJoin = function(prop) {
Expand Down Expand Up @@ -61,14 +61,14 @@ export default Ember.Component.extend({
this.send('close');
}
};
const registerClick = () => $(document).on('click.ember-modal-dialog', handleClick);
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);
this._super(...arguments);
},
willDestroyElement() {
$(document).off('click.ember-modal-dialog');
$(document).off(`click.ember-modal-dialog-${guidFor(this)}`);
this._super(...arguments);
},

Expand Down

0 comments on commit 64be133

Please sign in to comment.