PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.8.3
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.8.3
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / assets / js / modal.js

modal.js in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.8.3, at assets/js/modal.js

51 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 });