Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Ember Starter Kit</title>
  <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script src="http://builds.emberjs.com/tags/v1.11.3/ember-template-compiler.js"></script>
  <script src="http://builds.emberjs.com/tags/v1.11.3/ember.debug.js"></script>
</head>
<body>
  <script type="text/x-handlebars">
    <div {{action 'openModal' 'foo'}}>Open Foo</div>
    <div {{action 'openModal' 'bar'}}>Open Bar</div>
    
    {{my-modals}}
  </script>
  
  <script type="text/x-handlebars" data-template-name="components/foo-modal">
    Foo modal
    <span {{action 'close'}}>&times;</span>
  </script>
  
    <script type="text/x-handlebars" data-template-name="components/bar-modal">
    Bar modal
    <span {{action 'close'}}>&times;</span>
  </script>
  
</body>
</html>
 
/* Put your CSS here */
html, body {
  margin: 20px;
}
 
var app = Ember.Application.create();
app.ApplicationController = Ember.Controller.extend({
  modals: Ember.inject.service(),
  actions: {
    openModal: function(name) {
      this.get('modals').open(name);
    }
  }
});
app.ModalsService = Ember.Service.extend({
  containerView: null,
  open: function(name) {
    var Modal = this.container.lookupFactory('component:'+name+'-modal');
    var modal = Modal.create();
    this.get('containerView').pushObject(modal);
  },
  close: function() {
    this.get('containerView').popObject();
  }
});
app.MyModalsComponent = Ember.ContainerView.extend({
  elementId: 'my-modals',
  modals: Ember.inject.service(),
  didInsertElement: function() {
    this.set('modals.containerView', this);
  }
});
app.BaseModalComponent = Ember.Component.extend({
  modals: Ember.inject.service(),
  actions: {
    close: function() {
      this.get('modals').close();
    }
  }
});
app.FooModalComponent = app.BaseModalComponent.extend({
  layoutName: 'components/foo-modal'
});
app.BarModalComponent = app.BaseModalComponent.extend({
    layoutName: 'components/bar-modal'
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
amk221pro
0viewers