Skip to content

Commit

Permalink
click outside model
Browse files Browse the repository at this point in the history
  • Loading branch information
YueSteveYin committed Sep 15, 2024
1 parent 7c85f3b commit 971dd0e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
18 changes: 18 additions & 0 deletions assets/js/utils/clickoutside.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
document.addEventListener("DOMContentLoaded", function () {
const modal = document.querySelector('[x-show="showModal"]');

if (modal) {
const modalContent = modal.querySelector(".transform");

document.addEventListener("click", function (event) {
if (modal.__x && modal.__x.$data.showModal) {
console.log("click");

Check warning on line 9 in assets/js/utils/clickoutside.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
// Check if modal is currently open
if (!modalContent.contains(event.target)) {
// If the clicked element is not within the modal content
modal.__x.$data.showModal = false; // Use Alpine.js internal API to update the state
}
}
});
}
});
2 changes: 1 addition & 1 deletion hugo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
baseURL = "https://amplifycolorado.colabnews.co/"
baseURL = "http://localhost:1313/"
languageCode = "en-us"
title = ""
enableRobotsTXT = true
Expand Down
2 changes: 2 additions & 0 deletions layouts/_default/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ <h1>
x-transition:leave-end="opacity-0"
x-cloak
class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50"
@click="showModal = false"
>
<div
class="transform overflow-hidden rounded-lg bg-white shadow-xl transition-all sm:w-full sm:max-w-lg"
@click.stop
>
<div class="bg-gray px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6">
<button
Expand Down
2 changes: 2 additions & 0 deletions layouts/partials/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@
x-transition:leave-end="opacity-0"
x-cloak
class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50"
@click="showModal = false"
>
<div
class="transform overflow-hidden rounded-lg bg-white shadow-xl transition-all sm:w-full sm:max-w-lg"
@click.stop
>
<div class="bg-gray px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6">
<button
Expand Down

0 comments on commit 971dd0e

Please sign in to comment.