change LinksReform.js
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
// linksReform.js
|
||||||
|
|
||||||
export const linksReform = {
|
export const linksReform = {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -27,11 +29,9 @@ export const linksReform = {
|
|||||||
async removeBackdropElement() {
|
async removeBackdropElement() {
|
||||||
const backdrop = document.querySelector('div[data-hs-overlay-backdrop-template]');
|
const backdrop = document.querySelector('div[data-hs-overlay-backdrop-template]');
|
||||||
if (backdrop) {
|
if (backdrop) {
|
||||||
// Добавляем анимацию исчезновения
|
|
||||||
backdrop.style.transition = 'opacity 0.5s ease';
|
backdrop.style.transition = 'opacity 0.5s ease';
|
||||||
backdrop.style.opacity = '0';
|
backdrop.style.opacity = '0';
|
||||||
|
|
||||||
// Ждем завершения анимации
|
|
||||||
await new Promise(resolve => {
|
await new Promise(resolve => {
|
||||||
backdrop.addEventListener('transitionend', () => {
|
backdrop.addEventListener('transitionend', () => {
|
||||||
backdrop.remove();
|
backdrop.remove();
|
||||||
@@ -49,20 +49,23 @@ export const linksReform = {
|
|||||||
|
|
||||||
reactiveLinks.forEach(link => {
|
reactiveLinks.forEach(link => {
|
||||||
link.addEventListener('click', async (event) => {
|
link.addEventListener('click', async (event) => {
|
||||||
|
|
||||||
|
if (link.getAttribute('target') === '_blank') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.checkPathname(link.pathname)) return;
|
if (this.checkPathname(link.pathname)) return;
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const url = link.getAttribute('href');
|
const url = link.getAttribute('href');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Удаляем бэкдроп с анимацией перед переходом
|
|
||||||
await this.removeBackdropElement();
|
await this.removeBackdropElement();
|
||||||
this.clearBodyStyles();
|
this.clearBodyStyles();
|
||||||
|
|
||||||
this.$inertia.visit(url, {
|
this.$inertia.visit(url, {
|
||||||
preserveScroll: false,
|
preserveScroll: false,
|
||||||
onBefore: () => {
|
onBefore: () => {
|
||||||
// Дополнительная проверка перед переходом
|
|
||||||
this.removeBackdropElement().catch(() => {});
|
this.removeBackdropElement().catch(() => {});
|
||||||
this.clearBodyStyles();
|
this.clearBodyStyles();
|
||||||
return true;
|
return true;
|
||||||
@@ -70,7 +73,7 @@ export const linksReform = {
|
|||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error during navigation:', e);
|
console.error('Error during navigation:', e);
|
||||||
this.$inertia.visit(url); // Fallback на обычный переход
|
this.$inertia.visit(url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user