@hortonstudio/main 1.2.30 → 1.2.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autoInit/modal.js +18 -8
- package/index.js +1 -1
- package/package.json +1 -1
package/autoInit/modal.js
CHANGED
@@ -3,9 +3,8 @@ function initModal() {
|
|
3
3
|
transitionDuration: 0.3,
|
4
4
|
blurOpacity: 0.5,
|
5
5
|
breakpoints: {
|
6
|
-
mobile:
|
7
|
-
tablet:
|
8
|
-
desktop: 991
|
6
|
+
mobile: 767,
|
7
|
+
tablet: 991
|
9
8
|
}
|
10
9
|
};
|
11
10
|
|
@@ -13,8 +12,7 @@ function initModal() {
|
|
13
12
|
const width = window.innerWidth;
|
14
13
|
if (width <= config.breakpoints.mobile) return 'mobile';
|
15
14
|
if (width <= config.breakpoints.tablet) return 'tablet';
|
16
|
-
|
17
|
-
return 'desktop-large';
|
15
|
+
return 'desktop';
|
18
16
|
}
|
19
17
|
|
20
18
|
function shouldPreventModal(element) {
|
@@ -55,11 +53,23 @@ function initModal() {
|
|
55
53
|
});
|
56
54
|
}
|
57
55
|
|
58
|
-
|
56
|
+
// Store modal states that were closed due to prevention
|
57
|
+
let preventedModalStates = new Map();
|
58
|
+
|
59
|
+
function handleBreakpointChange() {
|
59
60
|
document.querySelectorAll('[data-hs-modalprevent]').forEach(element => {
|
60
|
-
|
61
|
+
const elementKey = element.getAttribute('data-hs-modal') + '_' + (element.id || element.className);
|
62
|
+
const shouldPrevent = shouldPreventModal(element);
|
63
|
+
const wasStoredAsOpen = preventedModalStates.get(elementKey);
|
64
|
+
|
65
|
+
if (shouldPrevent && element.x) {
|
66
|
+
preventedModalStates.set(elementKey, true);
|
61
67
|
element.x = 0;
|
62
68
|
closeModal(element);
|
69
|
+
} else if (!shouldPrevent && wasStoredAsOpen) {
|
70
|
+
preventedModalStates.delete(elementKey);
|
71
|
+
element.x = 1;
|
72
|
+
openModal(element);
|
63
73
|
}
|
64
74
|
});
|
65
75
|
}
|
@@ -97,7 +107,7 @@ function initModal() {
|
|
97
107
|
|
98
108
|
// Handle window resize to check for prevented modals
|
99
109
|
window.addEventListener('resize', function() {
|
100
|
-
|
110
|
+
handleBreakpointChange();
|
101
111
|
});
|
102
112
|
|
103
113
|
return { result: 'modal initialized' };
|
package/index.js
CHANGED