Last active
August 29, 2015 13:57
-
-
Save AaronGhent/9658819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @name: Modal Mixin | |
* @framework: Ember.JS | |
* @author: Aaron Ghent | |
*/ | |
App.ModalMixin = Ember.Mixin.create({ | |
defaultModal: 'modal', | |
modalsOpen: {}, | |
actions: { | |
openModal: function (modalName, model, modal) { | |
modal = modal || this.defaultModal; | |
if (model) { | |
this.controllerFor(modalName).set('model', model); | |
} | |
this.modalsOpen[modal] = true; | |
return this.render(modalName, { | |
into: 'application', | |
outlet: modal | |
}); | |
}, | |
closeModal: function (modal) { | |
modal = modal || this.defaultModal; | |
this.modalsOpen[modal] = false; | |
return this.disconnectOutlet({ | |
parentView: 'application', | |
outlet: modal | |
}); | |
}, | |
toggleModal: function (modalName, model, modal) { | |
modal = modal || this.defaultModal; | |
if (this.modalsOpen.hasOwnProperty(modal) && this.modalsOpen[modal]) { | |
this.send('closeModal'); | |
} else { | |
this.send('openModal', modalName, model, modal); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment