Skip to content

Commit

Permalink
feat: adds styles to selected lang in dropdown menu
Browse files Browse the repository at this point in the history
  • Loading branch information
migtarx committed Dec 4, 2023
1 parent 63fbca4 commit 1b22755
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ body {
.post a {
color: #27aff8; }

.menu-selected-lang {
color: #27aff8;
font-weight: 900; }

.post-title {
color: #27aff8; }

Expand Down
5 changes: 5 additions & 0 deletions themes/hello-friend/assets/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ body {
color: #27aff8;
}

.menu-selected-lang{
color: #27aff8;
font-weight: 900;
}

.post-title {
color: #27aff8;
}
Expand Down
14 changes: 11 additions & 3 deletions themes/hello-friend/assets/js/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const mobileMenuTrigger = document.querySelector(".menu-trigger");
const desktopMenu = document.querySelector(".menu__inner--desktop");
const desktopMenuTrigger = document.querySelector(".menu__sub-inner-more-trigger");
const menuMore = document.querySelector(".menu__sub-inner-more");
const currentPath = window.location.pathname;
const enLinks = document.getElementById('en-lang');
const esLinks = document.getElementById('es-lang');
const mobileQuery = getComputedStyle(document.body).getPropertyValue("--phoneWidth");
const isMobile = () => true;
const isMobileMenu = () => {
Expand All @@ -13,9 +16,16 @@ const isMobileMenu = () => {
};

// Common

isMobileMenu();

if (currentPath.startsWith('/es')) {
esLinks.classList.add('menu-selected-lang');
enLinks.classList.remove('menu-selected-lang');
} else {
enLinks.classList.add('menu-selected-lang');
esLinks.classList.remove('menu-selected-lang');
}

document.body.addEventListener("click", () => {
if (!isMobile() && menuMore && !menuMore.classList.contains("hidden")) {
menuMore.classList.add("hidden");
Expand All @@ -26,8 +36,6 @@ document.body.addEventListener("click", () => {

document.addEventListener('click', function(event) {
if (event.target.classList.contains('langChange')) {
const currentPath = window.location.pathname;

if (currentPath.startsWith('/es')) {
const newPath = currentPath.replace('/es', '');
window.location.href = window.location.origin + newPath;
Expand Down
4 changes: 2 additions & 2 deletions themes/hello-friend/layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</span>
<nav class="menu">
<ul class="menu__inner menu__inner">
<li class="langChange">ES</li>
<li class="langChange">EN</li>
<li id="es-lang" class="langChange">ES</li>
<li id="en-lang" class="langChange">EN</li>
</ul>
</nav>
</span>
Expand Down

0 comments on commit 1b22755

Please sign in to comment.