| 1 |
/** |
| 2 |
* Merchant Modal. |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
'use strict'; |
| 7 |
|
| 8 |
var merchant = merchant || {}; |
| 9 |
merchant.modal = { |
| 10 |
init: function init() { |
| 11 |
var self = this, |
| 12 |
els = document.querySelectorAll('[data-merchant-modal-trigger]'); |
| 13 |
if (!els.length) { |
| 14 |
return; |
| 15 |
} |
| 16 |
els.forEach(function (el) { |
| 17 |
el.addEventListener('click', self.openModal); |
| 18 |
}); |
| 19 |
document.querySelectorAll('[data-merchant-modal-close]').forEach(function (el) { |
| 20 |
el.addEventListener('click', self.buttonCloseModal); |
| 21 |
}); |
| 22 |
}, |
| 23 |
toggleBodyClass: function toggleBodyClass() { |
| 24 |
document.body.classList.toggle('merchant-modal-opened'); |
| 25 |
}, |
| 26 |
openModal: function openModal(event) { |
| 27 |
event.preventDefault(); |
| 28 |
event.stopPropagation(); |
| 29 |
var popupId = this.getAttribute('data-merchant-modal'), |
| 30 |
popup = document.querySelector('.merchant-modal[data-merchant-modal="' + popupId + '"]'); |
| 31 |
merchant.modal.toggleBodyClass(); |
| 32 |
popup.classList.add('show'); |
| 33 |
popup.addEventListener('click', merchant.modal.closeModal); |
| 34 |
}, |
| 35 |
closeModal: function closeModal(event) { |
| 36 |
if (event.target.closest('.merchant-modal-body') === null) { |
| 37 |
merchant.modal.toggleBodyClass(); |
| 38 |
this.classList.remove('show'); |
| 39 |
} |
| 40 |
}, |
| 41 |
buttonCloseModal: function buttonCloseModal(event) { |
| 42 |
event.preventDefault(); |
| 43 |
event.stopPropagation(); |
| 44 |
var popup = this.closest('.merchant-modal'); |
| 45 |
merchant.modal.toggleBodyClass(); |
| 46 |
popup.classList.remove('show'); |
| 47 |
} |
| 48 |
}; |
| 49 |
document.addEventListener('DOMContentLoaded', function () { |
| 50 |
merchant.modal.init(); |
| 51 |
}); |