Skip to content

Instantly share code, notes, and snippets.

@makepanic
Created June 20, 2016 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makepanic/95834c5d54935796e7ff68fc604d56f5 to your computer and use it in GitHub Desktop.
Save makepanic/95834c5d54935796e7ff68fc604d56f5 to your computer and use it in GitHub Desktop.
disconnectOutlet
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
modalOpen: false
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions:{
close(){
this.send('closeModal');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions:{
close(){
this.send('closeModal');
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
openModal: function(modalName) {
this.get('controller').set('modalOpen', true);
return this.render(modalName, {
into: 'application',
outlet: 'modal'
});
},
closeModal(){
this.get('controller').set('modalOpen', false);
this.disconnectOutlet({
outlet: 'modal',
parentView: 'application'
});
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
position: relative;
}
.modal{
background: rgba(33, 33, 33, .7);
}
.modal-open{
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
<h1>Welcome to {{appName}}</h1>
<h2>modalOpen: {{modalOpen}}</h2>
<br>
<br>
{{outlet}}
<br>
<br>
<div class="modal {{if modalOpen 'modal-open'}}">{{outlet 'modal'}}</div>
<button {{action 'openModal' 'modal1'}}>open modal 1</button>
<button {{action 'openModal' 'modal2'}}>open modal 2</button>
<h2>modal1</h2>
<button {{action 'close'}}>close</button>
<h2>modal2</h2>
<button {{action 'close'}}>close</button>
{
"version": "0.9.3",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment