const $ = require('jquery'); const bootstrap = require('bootstrap'); module.exports = class Modal { constructor({ title, body, primary, secondary }) { Object.assign(this, arguments[0]); this.$modal = $(``).appendTo(document.body); if (this.primary) { this.addPrimary(this.primary.label, this.primary.action); } if (this.secondary) { this.addSecondary(this.secondary.label, this.secondary.action); } this.show(); } addPrimary(label, action) { this.$primary = $(``) .appendTo(this.$modal.find('.modal-footer')) .on('click', () => action(this)); } addSecondary(label, action) { this.$primary = $(``) .appendTo(this.$modal.find('.modal-footer')) .on('click', () => action(this)); } show() { this.$modal.modal('show'); } hide() { this.$modal.modal('hide'); } getBody() { return this.$modal.find('.modal-body').get(0); } }