@profitlich/template-toolkit 7.6.1 → 7.7.0

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.
@@ -80,6 +80,14 @@ export class MenuToggle {
80
80
  }
81
81
  });
82
82
 
83
+ // Der Button sagt Hilfstechnik an, ob das Menü offen ist (ARIA Authoring
84
+ // Practices, «Disclosure»). Verborgen wird das Menü weiter über das CSS an
85
+ // `data-menu-active`, nicht mit `hidden`, damit Projekte das Öffnen animieren können.
86
+ this.#menuButton.setAttribute('aria-expanded', 'false');
87
+ if (this.#menu.id) {
88
+ this.#menuButton.setAttribute('aria-controls', this.#menu.id);
89
+ }
90
+
83
91
  this.#setBodyAttribute('data-menu-active', 'false');
84
92
  this.#setBodyAttribute('data-menu-moving', 'false');
85
93
  this.#fixElement.setAttribute('data-menu-fixed', 'false');
@@ -102,65 +110,98 @@ export class MenuToggle {
102
110
  return MenuToggle.#instance;
103
111
  }
104
112
 
105
- #toggleMenu() {
113
+ /**
114
+ * Öffnet das Menü – wie ein Klick auf den Menü-Button, aber von anderer Stelle,
115
+ * etwa wenn ein Projekt das Menü über eigene Knöpfe öffnet. Ist es schon offen,
116
+ * geschieht nichts.
117
+ */
118
+ open() {
106
119
  if (this.isActive) {
107
- this.isActive = false;
108
- document.body.removeEventListener('click', this.#bodyClickHandler);
109
- window.removeEventListener('resize', this.#resizeHandler);
110
- this.#setBodyAttribute('data-menu-active', 'false');
111
- if (this.#lockScroll) {
112
- this.#fixElement.setAttribute('data-menu-fixed', 'false');
113
- if (this.#shiftElement) {
114
- this.#shiftElement.style.marginRight = '';
115
- this.#shiftElement.style.width = '';
116
- }
117
- if (this.#fixElementIsBody) {
118
- this.#fixElement.style.paddingRight = '';
119
- }
120
- this.#fixElement.style.top = '';
121
- window.scrollTo(0, this.#y);
120
+ return;
121
+ }
122
+ this.isActive = true;
123
+ this.#menuButton.setAttribute('aria-expanded', 'true');
124
+ document.body.addEventListener('click', this.#bodyClickHandler);
125
+ this.#setBodyAttribute('data-menu-active', 'true');
126
+ if (this.#lockScroll) {
127
+ window.addEventListener('resize', this.#resizeHandler);
128
+ this.#setBodyAttribute('data-menu-moving', 'true');
129
+ if (!this.#deferPositionFixed) {
130
+ this.#applyFix();
122
131
  }
123
- this.#toggleEscape(false);
124
- } else {
125
- this.isActive = true;
126
- document.body.addEventListener('click', this.#bodyClickHandler);
127
- this.#setBodyAttribute('data-menu-active', 'true');
128
- if (this.#lockScroll) {
129
- window.addEventListener('resize', this.#resizeHandler);
130
- this.#setBodyAttribute('data-menu-moving', 'true');
131
- if (!this.#deferPositionFixed) {
132
+ setTimeout(() => {
133
+ if (this.#deferPositionFixed) {
132
134
  this.#applyFix();
133
135
  }
134
- setTimeout(() => {
135
- if (this.#deferPositionFixed) {
136
- this.#applyFix();
137
- }
138
- if (this.#shiftElement) {
139
- const marginOriginal = parseFloat(window.getComputedStyle(this.#menuButton).marginRight);
140
- this.#shiftElement.style.marginRight = `${marginOriginal + this.#scrollbarWidth}px`;
141
- this.#adjustShiftElementWidth();
142
- }
143
- this.#setBodyAttribute('data-menu-moving', 'false');
144
- }, this.#shiftDelay);
136
+ if (this.#shiftElement) {
137
+ const marginOriginal = parseFloat(window.getComputedStyle(this.#menuButton).marginRight);
138
+ this.#shiftElement.style.marginRight = `${marginOriginal + this.#scrollbarWidth}px`;
139
+ this.#adjustShiftElementWidth();
140
+ }
141
+ this.#setBodyAttribute('data-menu-moving', 'false');
142
+ }, this.#shiftDelay);
143
+ }
144
+ this.#toggleEscape(true);
145
+ this.#dispatchStatus();
146
+ }
147
+
148
+ /**
149
+ * Schliesst das Menü und stellt die Scroll-Position wieder her. Ist es schon zu,
150
+ * geschieht nichts.
151
+ */
152
+ close() {
153
+ if (!this.isActive) {
154
+ return;
155
+ }
156
+ this.isActive = false;
157
+ this.#menuButton.setAttribute('aria-expanded', 'false');
158
+ document.body.removeEventListener('click', this.#bodyClickHandler);
159
+ window.removeEventListener('resize', this.#resizeHandler);
160
+ this.#setBodyAttribute('data-menu-active', 'false');
161
+ if (this.#lockScroll) {
162
+ this.#fixElement.setAttribute('data-menu-fixed', 'false');
163
+ if (this.#shiftElement) {
164
+ this.#shiftElement.style.marginRight = '';
165
+ this.#shiftElement.style.width = '';
166
+ }
167
+ if (this.#fixElementIsBody) {
168
+ this.#fixElement.style.paddingRight = '';
145
169
  }
146
- this.#toggleEscape(true);
170
+ this.#fixElement.style.top = '';
171
+ window.scrollTo(0, this.#y);
172
+ }
173
+ this.#toggleEscape(false);
174
+ this.#dispatchStatus();
175
+ }
176
+
177
+ #toggleMenu() {
178
+ if (this.isActive) {
179
+ this.close();
180
+ } else {
181
+ this.open();
147
182
  }
183
+ }
184
+
185
+ #dispatchStatus() {
148
186
  const event = new CustomEvent('eventMenuestatus', {
149
187
  detail: { menueStatus: this.isActive }
150
188
  });
151
189
  document.dispatchEvent(event);
152
190
  }
153
191
 
154
- // Scrollbar-Ausgleich nur nötig, wenn der Body fixiert wird –
155
- // bei anderem #fixElement bleibt die Seiten-Scrollbar bestehen.
192
+ // Ausgeglichen wird nur, was das Fixieren an Breite wirklich freigibt. Bleibt die
193
+ // Scrollbar stehen – `overflow-y: scroll` oder `scrollbar-gutter: stable` an `html`,
194
+ // oder ein anderes #fixElement als der Body –, ist das nichts; ein Ausgleich um die
195
+ // volle Scrollbar-Breite schöbe den Inhalt dann nach links.
156
196
  #applyFix() {
157
- this.#scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
197
+ const widthBefore = document.documentElement.clientWidth;
158
198
  this.#y = window.scrollY;
199
+ this.#fixElement.style.top = `-${this.#y}px`;
200
+ this.#fixElement.setAttribute('data-menu-fixed', 'true');
201
+ this.#scrollbarWidth = Math.max(0, document.documentElement.clientWidth - widthBefore);
159
202
  if (this.#fixElementIsBody) {
160
203
  this.#fixElement.style.paddingRight = `${this.#scrollbarWidth}px`;
161
204
  }
162
- this.#fixElement.style.top = `-${this.#y}px`;
163
- this.#fixElement.setAttribute('data-menu-fixed', 'true');
164
205
  if (!this.#fixElementIsBody) {
165
206
  // Bei nicht-body-Fix-Element bleibt der window-Scroll erhalten; ohne Reset
166
207
  // erscheint ein absolut positioniertes Menü um den vorherigen Scroll-Betrag verschoben.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profitlich/template-toolkit",
3
- "version": "7.6.1",
3
+ "version": "7.7.0",
4
4
  "description": "Shared SCSS layout system, JS utilities, components and build scripts for profitlich template repos",
5
5
  "type": "module",
6
6
  "sass": "scss/forward.scss",