@caweb/framework 1.9.5 → 1.9.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/framework",
3
- "version": "1.9.5",
3
+ "version": "1.9.6",
4
4
  "description": "Official CAWebPublishing Framework frontend toolkit",
5
5
  "author": "CAWebPublishing",
6
6
  "homepage": "https://github.com/CAWebPublishing/framework#readme",
@@ -11,7 +11,8 @@ window.addEventListener('DOMContentLoaded', () => {
11
11
  document.querySelector('.utility-header'),
12
12
  ].filter(Boolean);
13
13
 
14
- let compactedElementsHeight = compactedElements.reduce((total, element) => {
14
+ const getCompactedElementsHeight = () => {
15
+ return compactedElements.reduce((total, element) => {
15
16
  if( element instanceof HTMLElement ){
16
17
  return total + element.clientHeight;
17
18
  }
@@ -19,6 +20,9 @@ window.addEventListener('DOMContentLoaded', () => {
19
20
  return total;
20
21
 
21
22
  }, 0);
23
+ }
24
+
25
+ let compactedElementsHeight = getCompactedElementsHeight();
22
26
 
23
27
  // lets collect the height of any fixed elements above the header.
24
28
  let topOffset = 0;
@@ -52,7 +56,6 @@ window.addEventListener('DOMContentLoaded', () => {
52
56
 
53
57
 
54
58
  const compactHeader = () => {
55
-
56
59
  // downscroll code passed the header height
57
60
  if (document.body.scrollTop >= header.offsetHeight ||
58
61
  document.documentElement.scrollTop >= header.offsetHeight
@@ -76,21 +79,32 @@ window.addEventListener('DOMContentLoaded', () => {
76
79
 
77
80
  };
78
81
 
82
+ // we need to update the compacted elements height if an alert is closed, so we listen for the alert close event and update the compacted elements height.
83
+ document.querySelectorAll('header .alerts [data-bs-dismiss="alert"]').forEach((closeButton) => {
84
+ closeButton.addEventListener('click', () => {
85
+ compactedElementsHeight = getCompactedElementsHeight();
86
+ document.querySelectorAll('#page-container [id]').forEach(updateScrollMarginTop);
87
+ });
88
+ });
89
+
79
90
  // for each element with an id we add the scroll-margin-top
80
- document.querySelectorAll('#page-container [id]').forEach((element) => {
91
+ const updateScrollMarginTop = (element) => {
81
92
  if( element instanceof HTMLElement ){
82
- let scrollMarginHeight = header.clientHeight + topOffset;
83
-
84
- // if the elements offsetTop is greater than twice the header size,
85
- // we can assume the header is compacted
86
- // so we need to subtract the compacted elements height from the scroll margin.
87
- if( element.offsetTop > scrollMarginHeight + (scrollMarginHeight / 2) ){
88
- scrollMarginHeight -= compactedElementsHeight;
89
- }
93
+ let scrollMarginHeight = header.clientHeight + topOffset;
94
+
95
+ // if the elements offsetTop is greater than twice the header size,
96
+ // we can assume the header is compacted
97
+ // so we need to subtract the compacted elements height from the scroll margin.
98
+ if( element.offsetTop > scrollMarginHeight + (scrollMarginHeight / 2) ){
99
+ scrollMarginHeight -= compactedElementsHeight;
100
+ }
101
+
102
+ element.style.scrollMarginTop = `${scrollMarginHeight}px`;
103
+ }
104
+ }
90
105
 
91
- element.style.scrollMarginTop = `${scrollMarginHeight}px`;
92
- }
93
- });
106
+ // add scroll margin top to all elements with an id, so that when we scroll to them, they are not hidden behind the header.
107
+ document.querySelectorAll('#page-container [id]').forEach(updateScrollMarginTop);
94
108
 
95
109
  // reset position on scroll
96
110
  window.addEventListener(
@@ -1 +0,0 @@
1
- <?php return array('dependencies' => array(), 'version' => 'a72d1beae01bd2203977');