Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make overlay clicks work on iOS automatically by adding cursor: pointer to the overlay div. #60

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ export default ModalDialog.extend({

View [the library](https://github.com/yapplabs/ember-key-responder) for more information.

## iOS

In order for taps on the overlay to be functional on iOS, a `cursor: pointer` style is added to the `div` when on iOS. If you need to change this behavior, subclass modal-dialog and override `makeOverlayClickableOnIOS`.

## Custom Modals

If you have various different styles of modal dialog in your app, it can be useful to subclass the dialog as a new component:
Expand Down
8 changes: 7 additions & 1 deletion addon/components/modal-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Ember from 'ember';
import template from '../templates/components/modal-dialog';
const dasherize = Ember.String.dasherize;
const computed = Ember.computed;
const get = Ember.get;
var isIOS = /iPad|iPhone|iPod/.test( navigator.userAgent );

const injectService = Ember.inject.service;
const reads = Ember.computed.reads;
Expand Down Expand Up @@ -115,7 +117,11 @@ export default Ember.Component.extend({
return 'middle right';
}
}),

makeOverlayClickableOnIOS: Ember.on('didInsertElement', function() {
if (isIOS && get(this, 'hasOverlay')) {
Ember.$('div[data-ember-modal-dialog-overlay]').css('cursor', 'pointer');
}
}),
actions: {
close: function() {
this.sendAction('close');
Expand Down
2 changes: 1 addition & 1 deletion addon/templates/current/components/modal-dialog.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#ember-wormhole to=destinationElementId renderInPlace=renderInPlace}}
{{#if hasOverlay}}
<div class="{{overlayClassNamesString}} {{if translucentOverlay 'translucent'}} {{overlay-class}}" {{action 'close'}}></div>
<div class="{{overlayClassNamesString}} {{if translucentOverlay 'translucent'}} {{overlay-class}}" {{action 'close'}} data-ember-modal-dialog-overlay></div>
{{/if}}
{{#if useEmberTether}}
{{#ember-tether classNameBindings="containerClassNamesString alignmentClass renderInPlaceClass container-class"
Expand Down
2 changes: 1 addition & 1 deletion addon/templates/lt-1-13/components/modal-dialog.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#ember-wormhole to=destinationElementId renderInPlace=renderInPlace}}
{{#if hasOverlay}}
<div {{bind-attr class="overlayClassNamesString translucentOverlay:translucent overlay-class"}} {{action 'close'}}></div>
<div {{bind-attr class="overlayClassNamesString translucentOverlay:translucent overlay-class"}} {{action 'close'}} data-ember-modal-dialog-overlay></div>
{{/if}}
{{#if useEmberTether}}
{{#ember-tether classNameBindings="containerClassNamesString alignmentClass renderInPlaceClass container-class"
Expand Down