mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-03 06:12:53 +02:00
Refactor HTML event handlers
This commit is contained in:
@@ -32,24 +32,22 @@ import Icon from './Icon.astro';
|
|||||||
|
|
||||||
<!-- Mobile Navigation Button -->
|
<!-- Mobile Navigation Button -->
|
||||||
<button
|
<button
|
||||||
id='show-mobile-navigation'
|
|
||||||
class='text-gray-400 hover:text-gray-50 block sm:hidden cursor-pointer'
|
class='text-gray-400 hover:text-gray-50 block sm:hidden cursor-pointer'
|
||||||
aria-label='Menu'
|
aria-label='Menu'
|
||||||
onclick="document.getElementById('mobile-navigation').classList.remove('hidden');"
|
show-mobile-nav
|
||||||
>
|
>
|
||||||
<Icon icon='hamburger' />
|
<Icon icon='hamburger' />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- Mobile Navigation Items -->
|
<!-- Mobile Navigation Items -->
|
||||||
<div
|
<div
|
||||||
id='mobile-navigation'
|
|
||||||
class='fixed top-0 bottom-0 left-0 right-0 z-40 bg-slate-900 items-center flex hidden'
|
class='fixed top-0 bottom-0 left-0 right-0 z-40 bg-slate-900 items-center flex hidden'
|
||||||
|
mobile-nav
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
id='close-mobile-navigation'
|
close-mobile-nav
|
||||||
class='text-gray-400 hover:text-gray-50 block cursor-pointer absolute top-6 right-6'
|
class='text-gray-400 hover:text-gray-50 block cursor-pointer absolute top-6 right-6'
|
||||||
aria-label='Close Menu'
|
aria-label='Close Menu'
|
||||||
onclick="document.getElementById('mobile-navigation').classList.add('hidden');"
|
|
||||||
>
|
>
|
||||||
<Icon icon='close' />
|
<Icon icon='close' />
|
||||||
</button>
|
</button>
|
||||||
@@ -80,3 +78,15 @@ import Icon from './Icon.astro';
|
|||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.querySelector('[show-mobile-nav]')?.addEventListener('click', () => {
|
||||||
|
document.querySelector('[mobile-nav]')?.classList.remove('hidden');
|
||||||
|
});
|
||||||
|
|
||||||
|
document
|
||||||
|
.querySelector('[close-mobile-nav]')
|
||||||
|
?.addEventListener('click', () => {
|
||||||
|
document.querySelector('[mobile-nav]')?.classList.add('hidden');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@@ -21,8 +21,7 @@ const { id, title, subtitle } = Astro.props;
|
|||||||
<div class='relative bg-white rounded-lg shadow popup-body'>
|
<div class='relative bg-white rounded-lg shadow popup-body'>
|
||||||
<button
|
<button
|
||||||
type='button'
|
type='button'
|
||||||
class='absolute top-3 right-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center'
|
class='absolute top-3 right-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center popup-close'
|
||||||
onclick='this.closest(".popup").classList.add("hidden")'
|
|
||||||
>
|
>
|
||||||
<Icon icon='close' />
|
<Icon icon='close' />
|
||||||
<span class='sr-only'>Close popup</span>
|
<span class='sr-only'>Close popup</span>
|
||||||
|
@@ -31,8 +31,9 @@ export class Popup {
|
|||||||
const target = e.target;
|
const target = e.target;
|
||||||
const popupBody = target.closest('.popup-body');
|
const popupBody = target.closest('.popup-body');
|
||||||
const closestPopup = target.closest('.popup');
|
const closestPopup = target.closest('.popup');
|
||||||
|
const closeBtn = target.closest('.popup-close');
|
||||||
|
|
||||||
if (popupBody) {
|
if (!closeBtn && popupBody) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ import Icon from './Icon.astro';
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
class='sticky top-0 border-b border-b-yellow-300 z-10 flex h-[37px]'
|
class='sticky top-0 border-b border-b-yellow-300 z-10 flex h-[37px]'
|
||||||
id='sticky-youtube-banner'
|
youtube-banner
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
href='https://youtube.com/theroadmap?sub_confirmation=1'
|
href='https://youtube.com/theroadmap?sub_confirmation=1'
|
||||||
@@ -17,9 +17,17 @@ import Icon from './Icon.astro';
|
|||||||
</a>
|
</a>
|
||||||
<button
|
<button
|
||||||
class='text-yellow-500 bg-yellow-200 hover:text-yellow-900 hover:bg-yellow-400 outline-0 px-2'
|
class='text-yellow-500 bg-yellow-200 hover:text-yellow-900 hover:bg-yellow-400 outline-0 px-2'
|
||||||
onclick='this.parentElement.classList.add("hidden")'
|
|
||||||
aria-label='Close'
|
aria-label='Close'
|
||||||
|
close-youtube-banner
|
||||||
>
|
>
|
||||||
<Icon icon='close' />
|
<Icon icon='close' />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document
|
||||||
|
.querySelector('[close-youtube-banner]')
|
||||||
|
?.addEventListener('click', () => {
|
||||||
|
document.querySelector('[youtube-banner]').remove();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
Reference in New Issue
Block a user