final
This commit is contained in:
@@ -91,6 +91,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
getLocalizedUrl(path) {
|
||||
const htmlLang = document.documentElement.lang;
|
||||
const currentLang = window.pll_current_language || this.getCurrentLangFromUrl();
|
||||
@@ -110,6 +111,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
return pathParts.length > 0 && languageCodes.includes(pathParts[0]) ? pathParts[0] : null;
|
||||
},
|
||||
|
||||
getCurrentBranch() {
|
||||
const isGymPage = window.location.pathname.includes('/gym/');
|
||||
return isGymPage ? 'gym' : 'main';
|
||||
},
|
||||
|
||||
open(modalName, params = {}) {
|
||||
const template = document.getElementById(`modal-template-${modalName}`);
|
||||
if (!template) return;
|
||||
@@ -156,6 +162,22 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
});
|
||||
}
|
||||
|
||||
const attrElements = this.content.querySelectorAll('[data-inject="card-attr"]');
|
||||
attrElements.forEach(el => {
|
||||
const parentDiv = el.closest('div');
|
||||
|
||||
if (params.cardAttr && params.cardAttr.trim() !== '') {
|
||||
el.textContent = params.cardAttr;
|
||||
if (parentDiv) {
|
||||
parentDiv.style.display = 'flex';
|
||||
}
|
||||
} else {
|
||||
if (parentDiv) {
|
||||
parentDiv.style.display = 'none';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (params.cardTime) {
|
||||
this.fillTimeInfo(JSON.parse(params.cardTime));
|
||||
}
|
||||
@@ -259,13 +281,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
this.overlay.classList.remove('opacity-0', 'invisible');
|
||||
this.overlay.classList.add('opacity-100', 'visible');
|
||||
|
||||
setTimeout(() => {
|
||||
if (this.container) {
|
||||
this.container.classList.remove('scale-90');
|
||||
this.container.classList.add('scale-100');
|
||||
}
|
||||
}, 10);
|
||||
|
||||
setTimeout(() => {
|
||||
if (this.closeBtn) this.closeBtn.focus();
|
||||
}, 350);
|
||||
@@ -274,6 +289,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
close() {
|
||||
if (this.modalStack.length === 0) return;
|
||||
|
||||
const currentModal = this.modalStack[this.modalStack.length - 1];
|
||||
|
||||
if (currentModal.name === 'welcome-branch') {
|
||||
const currentBranch = this.getCurrentBranch();
|
||||
localStorage.setItem('branch_choice_made', currentBranch);
|
||||
}
|
||||
|
||||
this.modalStack.pop();
|
||||
|
||||
if (this.modalStack.length > 0) {
|
||||
@@ -288,9 +310,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
hide() {
|
||||
if (!this.container || !this.overlay) return;
|
||||
|
||||
this.container.classList.remove('scale-100');
|
||||
this.container.classList.add('scale-90');
|
||||
|
||||
this.overlay.classList.remove('opacity-100', 'visible');
|
||||
this.overlay.classList.add('opacity-0', 'invisible');
|
||||
|
||||
@@ -303,4 +322,71 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
};
|
||||
|
||||
ModalSystem.init();
|
||||
|
||||
function checkWelcomeModal() {
|
||||
const isHomePage = window.location.pathname === '/' || window.location.pathname === '';
|
||||
const isGymPage = window.location.pathname.includes('/gym/');
|
||||
const hasChoiceMade = localStorage.getItem('branch_choice_made');
|
||||
|
||||
if ((isHomePage || isGymPage) && !hasChoiceMade) {
|
||||
setTimeout(function() {
|
||||
ModalSystem.open('welcome-branch');
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', function(e) {
|
||||
if (e.target.closest('.branch-card')) {
|
||||
e.preventDefault();
|
||||
|
||||
const branchCard = e.target.closest('.branch-card');
|
||||
const branch = branchCard.dataset.branch;
|
||||
|
||||
if (!branch) return;
|
||||
|
||||
localStorage.setItem('branch_choice_made', branch);
|
||||
|
||||
branchCard.classList.add('selecting');
|
||||
const button = branchCard.querySelector('button');
|
||||
if (button) {
|
||||
button.querySelector('span').textContent = 'Переходим...';
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
const isHomePage = window.location.pathname === '/' || window.location.pathname === '';
|
||||
const isGymPage = window.location.pathname.includes('/gym/');
|
||||
|
||||
if (branch === 'gym') {
|
||||
if (isGymPage) {
|
||||
ModalSystem.close();
|
||||
} else {
|
||||
window.location.href = '/gym/';
|
||||
}
|
||||
} else {
|
||||
if (isHomePage) {
|
||||
ModalSystem.close();
|
||||
} else {
|
||||
window.location.href = '/';
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('click', function(e) {
|
||||
const branchCard = e.target.closest('.branch-card');
|
||||
if (branchCard && !e.target.closest('.select-branch-btn')) {
|
||||
document.querySelectorAll('.branch-card').forEach(function(card) {
|
||||
card.classList.remove('selected');
|
||||
});
|
||||
branchCard.classList.add('selected');
|
||||
}
|
||||
});
|
||||
|
||||
checkWelcomeModal();
|
||||
|
||||
window.resetBranchChoice = function() {
|
||||
localStorage.removeItem('branch_choice_made');
|
||||
};
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user