@hortonstudio/main 1.2.29 → 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 CHANGED
@@ -1,10 +1,33 @@
1
1
  function initModal() {
2
2
  const config = {
3
3
  transitionDuration: 0.3,
4
- blurOpacity: 0.5
4
+ blurOpacity: 0.5,
5
+ breakpoints: {
6
+ mobile: 767,
7
+ tablet: 991
8
+ }
5
9
  };
6
10
 
11
+ function getCurrentBreakpoint() {
12
+ const width = window.innerWidth;
13
+ if (width <= config.breakpoints.mobile) return 'mobile';
14
+ if (width <= config.breakpoints.tablet) return 'tablet';
15
+ return 'desktop';
16
+ }
17
+
18
+ function shouldPreventModal(element) {
19
+ const preventAttr = element.getAttribute('data-hs-modalprevent');
20
+ if (!preventAttr) return false;
21
+
22
+ const currentBreakpoint = getCurrentBreakpoint();
23
+ const preventBreakpoints = preventAttr.split(',').map(bp => bp.trim());
24
+
25
+ return preventBreakpoints.includes(currentBreakpoint);
26
+ }
27
+
7
28
  function openModal(element) {
29
+ if (shouldPreventModal(element)) return;
30
+
8
31
  document.body.classList.add('u-overflow-clip');
9
32
 
10
33
  // Add blur to all other modals
@@ -30,6 +53,27 @@ function initModal() {
30
53
  });
31
54
  }
32
55
 
56
+ // Store modal states that were closed due to prevention
57
+ let preventedModalStates = new Map();
58
+
59
+ function handleBreakpointChange() {
60
+ document.querySelectorAll('[data-hs-modalprevent]').forEach(element => {
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);
67
+ element.x = 0;
68
+ closeModal(element);
69
+ } else if (!shouldPrevent && wasStoredAsOpen) {
70
+ preventedModalStates.delete(elementKey);
71
+ element.x = 1;
72
+ openModal(element);
73
+ }
74
+ });
75
+ }
76
+
33
77
  function toggleModal(element) {
34
78
  element.x = ((element.x || 0) + 1) % 2;
35
79
 
@@ -61,6 +105,11 @@ function initModal() {
61
105
  });
62
106
  });
63
107
 
108
+ // Handle window resize to check for prevented modals
109
+ window.addEventListener('resize', function() {
110
+ handleBreakpointChange();
111
+ });
112
+
64
113
  return { result: 'modal initialized' };
65
114
  }
66
115
 
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Version:1.2.29
1
+ // Version:1.2.31
2
2
 
3
3
  const API_NAME = 'hsmain';
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hortonstudio/main",
3
- "version": "1.2.29",
3
+ "version": "1.2.31",
4
4
  "description": "Animation and utility library for client websites",
5
5
  "main": "index.js",
6
6
  "type": "module",