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

Wormhole-less Modals #26

Merged
merged 1 commit into from
Apr 28, 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
11 changes: 9 additions & 2 deletions addon/components/modal-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export default Ember.Component.extend({
// the container div
layout: template,

"container-class": null, // set this from templates
'container-class': null, // set this from templates
containerClassNames: ['ember-modal-dialog'], // set this in a subclass definition
containerClassNamesString: computedJoin('containerClassNames'),

"overlay-class": null, // set this from templates
'overlay-class': null, // set this from templates
overlayClassNames: ['ember-modal-overlay'], // set this in a subclass definition
overlayClassNamesString: computedJoin('overlayClassNames'),

Expand All @@ -31,12 +31,19 @@ export default Ember.Component.extend({
}
}),

renderInPlaceClass: computed('renderInPlace', function() {
if (this.get('renderInPlace')) {
return 'ember-modal-dialog-in-place';
}
}),

destinationElementId: null, // injected
alignmentTarget: null, // view instance, passed in
alignment: 'center', // passed in
isPositioned: computed.notEmpty('alignmentTarget'),
hasOverlay: true,
translucentOverlay: false,
renderInPlace: false,

actions: {
close: function() {
Expand Down
4 changes: 2 additions & 2 deletions addon/templates/components/modal-dialog.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{#ember-wormhole to=destinationElementId}}
{{#ember-wormhole to=destinationElementId renderInPlace=renderInPlace}}
{{#if hasOverlay}}
<div {{bind-attr class="overlayClassNamesString translucentOverlay:translucent overlay-class"}} {{action 'close'}}></div>
{{/if}}
{{#ember-modal-dialog-positioned-container classNameBindings="containerClassNamesString alignmentClass container-class"
{{#ember-modal-dialog-positioned-container classNameBindings="containerClassNamesString alignmentClass renderInPlaceClass container-class"
alignment=alignment
alignmentTarget=alignmentTarget}}
{{yield}}
Expand Down
4 changes: 4 additions & 0 deletions app/styles/ember-modal-dialog/ember-modal-structure.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
.ember-modal-dialog {
z-index: 50;
position: fixed;

&.ember-modal-dialog-in-place {
position: relative;
}
}
4 changes: 4 additions & 0 deletions examples/in-place.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{#modal-dialog renderInPlace=true alignment='none'}}
<h1>Stop! Modal Time!</h1>
<p>In Place</p>
{{/modal-dialog}}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-modal-dialog",
"version": "0.4.1",
"version": "0.5.0",
"description": "An ember-cli addon for implementing modal dialogs",
"directories": {
"doc": "doc",
Expand Down Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"ember-cli-babel": "4.1.0",
"ember-cli-htmlbars": "^0.7.4",
"ember-wormhole": "0.2.1"
"ember-wormhole": "^0.3.1"
},
"keywords": [
"ember-addon"
Expand Down
18 changes: 18 additions & 0 deletions tests/acceptance/modal-dialogs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,22 @@ test('opening and closing modals', function(assert) {
assert.ok(Ember.$(`${modalRootElementSelector} ${dialogSelector}`).hasClass('my-cool-modal'), 'has provided containerClassNames');
}
});

click('#example-in-place button');
var dialogText = 'In Place';
var defaultSelector = [modalRootElementSelector, dialogSelector, ':contains(' + dialogText + ')'].join(' ');
var inPlaceDialogSelector = dialogSelector + '.ember-modal-dialog-in-place';
var inPlaceRootSelector = '#container-in-place';
var inPlaceSelector = [inPlaceRootSelector, inPlaceDialogSelector, ':contains(' + dialogText + ')'].join(' ');
var inPlaceCloseButton = [inPlaceRootSelector, inPlaceDialogSelector, 'button'].join(' ');
andThen(function() {
assert.isAbsent(defaultSelector);
assert.isPresentOnce(inPlaceSelector);
});

click(inPlaceCloseButton);
andThen(function() {
assert.isAbsent(defaultSelector);
assert.isAbsent(inPlaceSelector);
});
});
5 changes: 5 additions & 0 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default Ember.Controller.extend({
isShowingTranslucent: false,
isShowingCustomStyles: false,
isShowingAlignmentTarget: false,
isShowingSubclassed: false,
isShowingInPlace: false,
alignmentTargetDirection: 'right',
customContainerClassNames: 'custom-styles-modal-container',
nextAlignmentTargetDirection: function(){
Expand Down Expand Up @@ -63,6 +65,9 @@ export default Ember.Controller.extend({
toggleSubclassed: function(){
this.toggleProperty('isShowingSubclassed');
},
toggleInPlace: function() {
this.toggleProperty('isShowingInPlace');
},
closeAlignmentTargetSelector: function() {
this.set('isShowingAlignmentTargetSelector', false);
this.set('alignmentTargetDirection', 'right');
Expand Down
12 changes: 12 additions & 0 deletions tests/dummy/app/initializers/register-subclassed-modals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
after: 'add-modals-container',
name: 'custom-modals',
initialize(_, application) {
var customModals = ['my-cool-modal-dialog'];
customModals.forEach(function(customModal) {
application.inject('component:' + customModal,
'destinationElementId',
'config:modals-container-id');
});
}
};
6 changes: 6 additions & 0 deletions tests/dummy/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ body {
width: 500px;
}

#container-in-place {
min-height: 10px;
border: dotted 2px lime;
padding: 20px;
}

button {
padding: 4px 8px;
border-radius: 4px;
Expand Down
16 changes: 16 additions & 0 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,19 @@
{{/my-cool-modal-dialog}}
{{/if}}
</div>

<div class='example' id='example-in-place'>
<h2>In Place</h2>
<button {{action 'toggleInPlace'}}>Do It</button>
{{code-snippet name='in-place.hbs'}}
<div id='container-in-place'>
I AM THE CONTAINER
{{#if isShowingInPlace}}
{{#modal-dialog close='toggleInPlace' renderInPlace=true alignment='none'}}
<h1>Stop! Modal Time!</h1>
<p>In Place</p>
<button {{action 'toggleInPlace'}}>Close</button>
{{/modal-dialog}}
{{/if}}
</div>
</div>