Skip to content
Snippets Groups Projects
Commit 92ef9519 authored by xaralis's avatar xaralis
Browse files

Fix navbar subnav JS bug

parent d7182230
No related branches found
No related tags found
No related merge requests found
Pipeline #883 passed
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
<a href="#" data-href="{{ link.templates-homepage }}" class="navbar-menu__link">Hlavní strana</a> <a href="#" data-href="{{ link.templates-homepage }}" class="navbar-menu__link">Hlavní strana</a>
</li> </li>
<li class="navbar-menu__item"> <li class="navbar-menu__item">
<ui-navbar-subitem label="Lidé" href="{{ link.templates-people }}"> <ui-navbar-subitem label="Lidé">
<ul class="navbar-menu__submenu"> <ul class="navbar-menu__submenu">
<li><a href="#" class="navbar-menu__link">Delší link co je delší než hlavní menu položka</a></li> <li><a href="#" data-href="{{ link.templates-people }}" class="navbar-menu__link">Delší link co je delší než hlavní menu položka</a></li>
</ul> </ul>
</ui-navbar-subtitem> </ui-navbar-subtitem>
</li> </li>
...@@ -42,7 +42,11 @@ ...@@ -42,7 +42,11 @@
</ui-navbar-subtitem> </ui-navbar-subtitem>
</li> </li>
<li class="navbar-menu__item"> <li class="navbar-menu__item">
<a href="#" data-href="{{ link.templates-elections }}" class="navbar-menu__link">Volby</a> <ui-navbar-subitem label="Volby">
<ul class="navbar-menu__submenu">
<li><a href="#" data-href="{{ link.templates-elections }}" class="navbar-menu__link">Volební rozcestník</a></li>
</ul>
</ui-navbar-subtitem>
</li> </li>
<li class="navbar-menu__item"> <li class="navbar-menu__item">
<a href="#" data-href="{{ link.templates-pirate-center }}" class="navbar-menu__link">Pirátské centrum</a> <a href="#" data-href="{{ link.templates-pirate-center }}" class="navbar-menu__link">Pirátské centrum</a>
......
...@@ -9,17 +9,15 @@ ...@@ -9,17 +9,15 @@
</template> </template>
<script> <script>
import screens from "../../../../screens"; import { isLgScreenSize } from "../../utils";
const lgScreenSize = parseInt(screens.lg.replace("px", ""), 10);
export default { export default {
data() { data() {
return { return {
isLgScreenSize: this.getWindowWidth() >= lgScreenSize, isLgScreenSize: isLgScreenSize(),
show: false, show: false,
resizeHandler: () => { resizeHandler: () => {
this.$data.isLgScreenSize = this.getWindowWidth() >= lgScreenSize; this.$data.isLgScreenSize = isLgScreenSize();
}, },
}; };
}, },
...@@ -43,9 +41,6 @@ export default { ...@@ -43,9 +41,6 @@ export default {
} }
}, },
methods: { methods: {
getWindowWidth() {
return Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
},
handleClick() { handleClick() {
if (this.$props.href) { if (this.$props.href) {
window.location = this.$props.href; window.location = this.$props.href;
......
<script> <script>
import UiNavbarSubitem from "./NavbarSubitem"; import UiNavbarSubitem from "./NavbarSubitem";
import screens from "../../../../screens"; import { isLgScreenSize } from "../../utils";
const lgScreenSize = parseInt(screens.lg.replace("px", ""), 10);
export default { export default {
components: { components: {
...@@ -10,18 +8,13 @@ ...@@ -10,18 +8,13 @@
}, },
data() { data() {
return { return {
isLgScreenSize: this.getWindowWidth() >= lgScreenSize, isLgScreenSize: isLgScreenSize(),
show: false, show: false,
resizeHandler: () => { resizeHandler: () => {
this.$data.isLgScreenSize = this.getWindowWidth() >= lgScreenSize; this.$data.isLgScreenSize = isLgScreenSize();
}, },
}; };
}, },
methods: {
getWindowWidth() {
return Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
}
},
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
window.addEventListener("resize", this.$data.resizeHandler); window.addEventListener("resize", this.$data.resizeHandler);
......
<template> <template>
<div @mouseenter="show = true" @mouseleave="show = false"> <div @mouseenter="onMouseEnter" @mouseleave="onMouseLeave">
<span class="navbar-menu__link navbar-menu__submenu-toggle" :class="{'navbar-menu__submenu-toggle--open': show}" @click="handleClick">{{ label }}</span> <span class="navbar-menu__link navbar-menu__submenu-toggle" :class="{'navbar-menu__submenu-toggle--open': show}" @click="handleClick">{{ label }}</span>
<div :class="{'navbar-menu__submenu-wrap--show': show}" class="navbar-menu__submenu-wrap"> <div :class="{'navbar-menu__submenu-wrap--show': show}" class="navbar-menu__submenu-wrap">
<slot> <slot>
</slot> </slot>
...@@ -10,6 +9,8 @@ ...@@ -10,6 +9,8 @@
</template> </template>
<script> <script>
import { isLgScreenSize } from "../../utils";
export default { export default {
data() { data() {
return { return {
...@@ -25,6 +26,16 @@ export default { ...@@ -25,6 +26,16 @@ export default {
} }
}, },
methods: { methods: {
onMouseEnter() {
if (isLgScreenSize()) {
this.$data.show = true;
}
},
onMouseLeave() {
if (isLgScreenSize()) {
this.$data.show = false;
}
},
handleClick() { handleClick() {
if (this.$props.href) { if (this.$props.href) {
window.location = this.$props.href; window.location = this.$props.href;
......
import screens from "../../screens";
const lgScreenSize = parseInt(screens.lg.replace("px", ""), 10);
export const forEachNode = function (array, callback, scope) { export const forEachNode = function (array, callback, scope) {
for (var i = 0; i < array.length; i++) { for (var i = 0; i < array.length; i++) {
callback.call(scope, array[i]); // passes back stuff we need callback.call(scope, array[i]); // passes back stuff we need
} }
}; };
export function getWindowWidth() {
return Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
}
export function isLgScreenSize() {
return getWindowWidth() >= lgScreenSize;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment