From 27b03eea04d7ff9e32d5d8e84b4f5702821a17b0 Mon Sep 17 00:00:00 2001 From: Andrew Croce Date: Thu, 20 Sep 2018 11:44:59 -0400 Subject: [PATCH] Emit and respond to a modalOpen event, which conditionally adds a class to the body --- js/index.js | 10 ++++++++++ js/mixins/modal.js | 2 ++ 2 files changed, 12 insertions(+) diff --git a/js/index.js b/js/index.js index 2d195ce8..653038f4 100644 --- a/js/index.js +++ b/js/index.js @@ -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) diff --git a/js/mixins/modal.js b/js/mixins/modal.js index 4f6af652..bb2bba05 100644 --- a/js/mixins/modal.js +++ b/js/mixins/modal.js @@ -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() {