Skip to content

Commit

Permalink
Fix scripts import & optimizing (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiboux authored Nov 8, 2024
1 parent 51cf37f commit 2cd36a3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/app/src/components/Modal.astro
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@
}
</style>

<script lang="ts">
<script>
const modalDismissers = document.querySelectorAll('.modal [data-dismiss="modal"]')
for (const modalDismisser of modalDismissers)
{
modalDismisser.addEventListener('click', (event) =>
{
event.preventDefault()
const modal = modalDismisser.closest('.modal')
modal.classList.toggle('show')
modal?.classList.toggle('show')
})
}
</script>
6 changes: 3 additions & 3 deletions app/app/src/components/Navbar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ const navbarplus = yaml.load(navbarplusYml) as any
}
</style>

<script lang="ts">
<script>
const navbarTogglers = document.querySelectorAll('.navbar .navbar-toggler')
for (const navbarToggler of navbarTogglers)
{
navbarToggler.addEventListener('click', (event) =>
{
event.preventDefault()
const navbarCollapse = navbarToggler.parentElement.querySelector('.navbar-collapse')
const navbarCollapse = navbarToggler.parentElement?.querySelector('.navbar-collapse')
navbarCollapse?.classList.toggle('show')
})
}
Expand All @@ -211,7 +211,7 @@ for (const dropdownToggler of dropdownTogglers)
dropdownToggler.addEventListener('click', (event) =>
{
event.preventDefault()
const dropdownMenu = dropdownToggler.parentElement.querySelector('.dropdown-menu')
const dropdownMenu = dropdownToggler.parentElement?.querySelector('.dropdown-menu')
dropdownMenu?.classList.toggle('show')
})
}
Expand Down
7 changes: 7 additions & 0 deletions app/app/src/components/Scripts.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
---

<script src="~/scripts/body-height.ts"></script>
<script src="~/scripts/standalone-app.js"></script>
<script src="~/scripts/carousel.ts"></script>
<script src="~/scripts/invalid-links.js"></script>
12 changes: 2 additions & 10 deletions app/app/src/layouts/Default.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import '@fontsource/roboto/400.css'
import '@fontsource/roboto/500.css'
import '@fontsource/roboto/700.css'
import '~/styles/tiles.css'
import bodyHeightJs from '~/scripts/body-height.ts?url'
import standaloneAppJs from '~/scripts/standalone-app.ts?url'
import carouselJs from '~/scripts/carousel.ts?url'
import invalidLinksJs from '~/scripts/invalid-links.ts?url'
import Layout from '~/layouts/Layout.astro'
import type { Props as BaseProps } from '~/layouts/Layout.astro'
Expand All @@ -15,6 +11,7 @@ import Modal from '../components/Modal.astro'
import Navbar from '../components/Navbar.astro'
import Newsline from '../components/Newsline.astro'
import Footer from '~/components/Footer.astro'
import Scripts from '~/components/Scripts.astro'
export interface Props extends BaseProps
{
Expand Down Expand Up @@ -58,12 +55,7 @@ const baseProps: BaseProps = {

</Layout>

{!noScripts && (
<script src={bodyHeightJs}></script>
<script src={standaloneAppJs}></script>
<script src={carouselJs}></script>
<script src={invalidLinksJs}></script>
)}
{!noScripts && <Scripts />}

<style lang="scss" is:global>
html, body {
Expand Down

0 comments on commit 2cd36a3

Please sign in to comment.