Emit and respond to a modalOpen event, which conditionally adds a class to the body

This commit is contained in:
Andrew Croce 2018-09-20 11:44:59 -04:00
parent c1e6bc0f84
commit 27b03eea04
2 changed files with 12 additions and 0 deletions

View File

@ -41,8 +41,18 @@ const app = new Vue({
CcpoApproval,
LocalDatetime
},
mounted: function() {
this.$on('modalOpen', isOpen => {
if (isOpen) {
document.body.className += ' modal-open'
} else {
document.body.className = document.body.className.replace(' modal-open', '')
}
})
const modalOpen = document.querySelector("#modalOpen")
if (modalOpen) {
const modal = modalOpen.getAttribute("data-modal")
this.openModal(modal)

View File

@ -2,9 +2,11 @@ export default {
methods: {
closeModal: function(name) {
this.modals[name] = false
this.$emit('modalOpen', false)
},
openModal: function (name) {
this.modals[name] = true
this.$emit('modalOpen', true)
}
},
data: function() {