@progressive-development/pd-page 0.1.25 → 0.1.26

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/PdMenu.js +18 -14
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Progressive development page helper, teaser, menu, footer.",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "author": "PD Progressive Development",
6
- "version": "0.1.25",
6
+ "version": "0.1.26",
7
7
  "main": "index.js",
8
8
  "module": "index.js",
9
9
  "scripts": {
package/src/PdMenu.js CHANGED
@@ -207,7 +207,7 @@ export class PdMenu extends LitElement {
207
207
  }
208
208
 
209
209
  firstUpdated() {
210
- const doSomething = scrollPos => {
210
+ const doSomething = (scrollPos) => {
211
211
  let activeSecIndex = -1;
212
212
  let distance = scrollPos > 300 ? 5000 : 300; // start value, define when first item is active
213
213
  this.menuItems.forEach((item, index) => {
@@ -224,7 +224,7 @@ export class PdMenu extends LitElement {
224
224
  };
225
225
 
226
226
  let ticking = false;
227
- document.addEventListener('scroll', () => {
227
+ this.addEventListener('scroll', () => {
228
228
  const lastKnownScrollPosition = window.scrollY;
229
229
  if (!ticking) {
230
230
  window.requestAnimationFrame(() => {
@@ -234,9 +234,6 @@ export class PdMenu extends LitElement {
234
234
  ticking = true;
235
235
  }
236
236
  });
237
- }
238
-
239
- render() {
240
237
 
241
238
  installMediaQueryWatcher(`(max-width: 700px)`, matches => {
242
239
  if (matches) {
@@ -245,6 +242,9 @@ export class PdMenu extends LitElement {
245
242
  this._smallScreen = false;
246
243
  }
247
244
  });
245
+ }
246
+
247
+ render() {
248
248
 
249
249
  return html`
250
250
  <div class="menu-container">
@@ -275,8 +275,7 @@ export class PdMenu extends LitElement {
275
275
  class="item ${checkActiveClass && this._activeSecIndex === index + 1
276
276
  ? 'active'
277
277
  : ''}"
278
- data-sec="${item.sec}"
279
- data-route="${item.route}"
278
+ data-key="${item.key}"
280
279
  @click="${this._menuItemClicked}"
281
280
  >
282
281
  ${item.icon && !disableIcons
@@ -297,20 +296,25 @@ export class PdMenu extends LitElement {
297
296
  }
298
297
 
299
298
  _menuItemClicked(e) {
300
-
301
- const secParam = e.target.dataset.sec;
302
- const routeParam = e.target.dataset.route;
303
- if (secParam !== 'undefined' && secParam !== '') {
299
+
300
+ // get menu item
301
+ const keyParam = e.target.dataset.key;
302
+ const menuItem = this.menuItems.filter(mi => mi.key === keyParam)[0];
303
+
304
+ if (menuItem.sec && menuItem.sec !== '') {
304
305
  // TODO: Check if element exists
305
- this._scrollToContent(secParam);
306
- } else if (routeParam !== 'undefined' && routeParam !== '') {
306
+ this._scrollToContent(menuItem.sec);
307
+ } else if (menuItem.route && menuItem.route !== '') {
307
308
  this.dispatchEvent(
308
309
  new CustomEvent('route-event', {
309
310
  detail: {
310
- route: routeParam === 'back' ? '' : routeParam,
311
+ route: menuItem.route === 'back' ? '' : menuItem.route,
311
312
  },
312
313
  })
313
314
  );
315
+ } else if (menuItem.action) {
316
+ // call action
317
+ menuItem.action();
314
318
  }
315
319
 
316
320
  // close menu if open