WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit b98179b

Browse files
committed
feat(header): Use click instead of hover for desktop dropdown-menu
Signed-off-by: Khusika Dhamar Gusti <[email protected]>
1 parent 7bf5288 commit b98179b

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

assets/css/_partial/_header.scss

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,17 @@ header {
242242
}
243243
}
244244

245-
&:hover .dropdown-menu,
246-
&:focus-within .dropdown-menu {
245+
&.active .dropdown-menu {
247246
display: block;
248247
}
249-
&:hover .dropdown-toggle i {
248+
&.active .dropdown-toggle i {
250249
@include transform(rotate(180deg));
251250
}
252-
&:hover {
251+
&.active {
253252
color: $header-hover-color;
254253
[theme=dark] & { color: $header-hover-color-dark; }
255254
}
256255

257-
&.active .dropdown-toggle i {
258-
@include transform(rotate(180deg));
259-
}
260-
261256
.dropdown-item {
262257
display: block;
263258
padding: 0 .5rem !important;

assets/js/theme.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,25 @@ class Theme {
128128
});
129129
}
130130

131-
initDesktopMenu() {
131+
initMenuDesktop() {
132132
if (this.util.isMobile()) return;
133-
this.util.forEach(document.querySelectorAll('#header-desktop .has-children .dropdown-item.active'), $activeChild => {
134-
const $parentMenuItem = $activeChild.closest('.has-children');
135-
if ($parentMenuItem) {
136-
const $parentLink = $parentMenuItem.querySelector('a.dropdown-toggle');
137-
if ($parentLink) $parentLink.style.fontWeight = 'bold';
133+
134+
this.util.forEach(document.querySelectorAll('#header-desktop .dropdown-item.active'), $activeChild => {
135+
$activeChild.closest('.has-children')?.querySelector('a.dropdown-toggle')?.classList.add('active');
136+
});
137+
138+
document.addEventListener('click', e => {
139+
const $toggle = e.target.closest('a.dropdown-toggle');
140+
if ($toggle && $toggle.parentElement.matches('#header-desktop .has-children')) {
141+
e.preventDefault();
142+
const $menuItem = $toggle.parentElement;
143+
const isActive = $menuItem.classList.contains('active');
144+
this.util.forEach(document.querySelectorAll('#header-desktop .has-children.active'), el => el.classList.remove('active'));
145+
if (!isActive) {
146+
$menuItem.classList.add('active');
147+
}
148+
} else if (!e.target.closest('#header-desktop .has-children')) {
149+
this.util.forEach(document.querySelectorAll('#header-desktop .has-children.active'), el => el.classList.remove('active'));
138150
}
139151
});
140152
}
@@ -799,9 +811,9 @@ class Theme {
799811
this.initSVGIcon();
800812
this.initTwemoji();
801813
this.initMenuMobile();
814+
this.initMenuDesktop();
802815
this.initSwitchTheme();
803816
this.initSearch();
804-
this.initDesktopMenu();
805817
this.initDetails();
806818
this.initLightGallery();
807819
this.initHighlight();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"scripts": {
2020
"build": "rm -f -r exampleSite/public && hugo --source=exampleSite --gc",
2121
"build-lunr-segmentit": "browserify src/lib/lunr.segmentit.js -o assets/lib/lunr/lunr.segmentit.js -t babelify --presets @babel/preset-env --presets minify",
22-
"purgejs": "npx mkdirp exampleSite/assets/js && sed '652,656d;674,723d;726,729d;815d' assets/js/theme.js > exampleSite/assets/js/theme.js",
22+
"purgejs": "npx mkdirp exampleSite/assets/js && sed '664,668d;686,735d;738,741d;827d' assets/js/theme.js > exampleSite/assets/js/theme.js",
2323
"deploy": "npm run purgejs && hugo --source=exampleSite --gc --minify && rm -rf exampleSite/assets/js",
2424
"start": "hugo server --source=exampleSite -D --disableFastRender",
2525
"start-production": "hugo server --source=exampleSite -D --disableFastRender -e production",

0 commit comments

Comments
 (0)