Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 63 additions & 5 deletions resources/js/Jetstream/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,50 @@
<script>
import { onMounted, onUnmounted } from "vue";

let openModalCount = 0;
let originalBodyOverflow = "";
let originalBodyPaddingRight = "";

const lockBodyScroll = () => {
if (typeof window === "undefined") {
return;
}

if (openModalCount === 0) {
originalBodyOverflow = document.body.style.overflow;
originalBodyPaddingRight = document.body.style.paddingRight;

const scrollbarWidth =
window.innerWidth - document.documentElement.clientWidth;
const bodyPaddingRight =
parseFloat(window.getComputedStyle(document.body).paddingRight) ||
0;

document.body.style.overflow = "hidden";

if (scrollbarWidth > 0) {
document.body.style.paddingRight = `${
bodyPaddingRight + scrollbarWidth
}px`;
}
}

openModalCount += 1;
};

const unlockBodyScroll = () => {
if (typeof window === "undefined" || openModalCount === 0) {
return;
}

openModalCount -= 1;

if (openModalCount === 0) {
document.body.style.overflow = originalBodyOverflow;
document.body.style.paddingRight = originalBodyPaddingRight;
}
};

export default {
props: {
show: {
Expand Down Expand Up @@ -78,14 +122,19 @@ export default {
onMounted(() => document.addEventListener("keydown", closeOnEscape));
onUnmounted(() => {
document.removeEventListener("keydown", closeOnEscape);
document.body.style.overflow = null;
});

return {
close,
};
},

data() {
return {
bodyScrollLocked: false,
};
},

computed: {
maxWidthClass() {
return {
Expand All @@ -107,13 +156,22 @@ export default {
show: {
immediate: true,
handler: function (show) {
if (show) {
document.body.style.overflow = "hidden";
} else {
document.body.style.overflow = null;
if (show && !this.bodyScrollLocked) {
lockBodyScroll();
this.bodyScrollLocked = true;
} else if (!show && this.bodyScrollLocked) {
unlockBodyScroll();
this.bodyScrollLocked = false;
}
},
},
},

unmounted() {
if (this.bodyScrollLocked) {
unlockBodyScroll();
this.bodyScrollLocked = false;
}
},
};
</script>
19 changes: 12 additions & 7 deletions resources/js/Shared/ManageAuthor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1474,17 +1474,22 @@ export default {
* Handles success/error states and UI updates
*/
deleteAuthor() {
this.authorsForm.delete(route("author.delete", this.project.id), {
preserveScroll: true,
preserveState: true,
onSuccess: () => {
axios
.delete(route("author.delete", this.project.id), {
data: {
authors: this.authorsForm.authors,
},
headers: {
Accept: "application/json",
},
})
.then(() => {
router.reload({ only: ["project"] });
this.loadInitial();
this.authorsForm.reset();
this.closeDeleteConfirm();
},
onError: (err) => console.error(err),
});
})
.catch((err) => console.error(err));
},

/**
Expand Down
26 changes: 14 additions & 12 deletions resources/js/Shared/ManageCitation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -968,19 +968,21 @@ export default {
* Execute delete request to backend API
*/
deleteCitation() {
this.citationsForm.delete(
route("citation.delete", this.project.id),
{
preserveScroll: true,
preserveState: true,
onSuccess: () => {
router.reload({ only: ["project"] });
this.loadInitial();
this.closeDeleteConfirm();
axios
.delete(route("citation.delete", this.project.id), {
data: {
citations: this.citationsForm.citations,
},
onError: (err) => console.error(err),
}
);
headers: {
Accept: "application/json",
},
})
.then(() => {
router.reload({ only: ["project"] });
this.loadInitial();
this.closeDeleteConfirm();
})
.catch((err) => console.error(err));
},

// =============================================================================
Expand Down
Loading