Skip to content

Commit

Permalink
Fix bug in specifying incorrect overlay selector on iOS
Browse files Browse the repository at this point in the history
- alternate implementation to #244
  • Loading branch information
lukemelia committed Mar 3, 2018
1 parent b76f90e commit 2d9bc93
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions addon/components/basic-dialog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { on } from '@ember/object/evented';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { isEmpty } from '@ember/utils';
Expand Down Expand Up @@ -52,20 +51,11 @@ export default Component.extend({
return this.get('overlayPosition') === 'sibling';
}),

isIOS: computed(function() {
return /iPad|iPhone|iPod/.test(navigator.userAgent);
}),

makeOverlayClickableOnIOS: on('didInsertElement', function() {
if (this.get('isIOS')) {
document.querySelector('div[data-ember-modal-dialog-overlay]').style.cursor = 'pointer';
}
}),

didInsertElement() {
if (!this.get('clickOutsideToClose')) {
return;
}
this.makeOverlayClickableOnIOS();

this.handleClick = ({ target }) => {
// if the click has already resulted in the target
Expand Down Expand Up @@ -93,7 +83,7 @@ export default Component.extend({
setTimeout(registerClick);

if (this.get('isIOS')) {
const registerTouch = () => document.addEventListener.on('touchend', this.handleClick);
const registerTouch = () => document.addEventListener('touchend', this.handleClick);
setTimeout(registerTouch);
}
this._super(...arguments);
Expand All @@ -105,5 +95,18 @@ export default Component.extend({
document.removeEventListener('touchend', this.handleClick);
}
this._super(...arguments);
},

isIOS: computed(function() {
return /iPad|iPhone|iPod/.test(navigator.userAgent);
}),

makeOverlayClickableOnIOS: function() {
if (this.get('isIOS')) {
let overlayEl = document.querySelector('div[data-emd-overlay]');
if (overlayEl) {
overlayEl.style.cursor = 'pointer';
}
}
}
});

0 comments on commit 2d9bc93

Please sign in to comment.