Raise drawer z-index above the slider and stretch banner images full width. Co-authored-by: Cursor <cursoragent@cursor.com>
421 lines
13 KiB
JavaScript
Executable File
421 lines
13 KiB
JavaScript
Executable File
function tr(string) {
|
|
if (window.locale === 'tm') {
|
|
return string
|
|
}
|
|
|
|
return {
|
|
'TÜRKMENISTANYŇ "TÜRKMENBAŞY" PAÝDARLAR TÄJIRÇILIK BANKY': 'АКЦИОНЕРНЫЙ КОММЕРЧЕСКИЙ БАНК ТУРКМЕНИСТАНА «ТУРКМЕНБАШИ»',
|
|
'Sorag-jogap merkezi:': 'Вопросы:',
|
|
'Gözleg': 'Поиск',
|
|
'«ALTYN ASYR» töleg ulgamynyň bankomatlaryny ulanmak boýunça gözükdiriji': 'Руководство по использованию банкоматов платежной системы «ALTYN ASYR»',
|
|
'Töleg terminalyny ulanmak boýunça gözükdiriji': 'Руководство по использованию платежного терминала',
|
|
'Töleg terminallaryny gurnamak üçin hödürlenmeli resminamalaryň sanawy': 'Перечень документов, которые необходимо предоставить для установки платежных терминалов',
|
|
'TÄZELIKLER WE MAKALALAR': 'НОВОСТИ И БЛОГИ',
|
|
'Çandybil şaýoly, 121': 'Чандыбил Шайолы',
|
|
'Aşgabat, Türkmenistan, 744000': 'Ашхабад, Туркменистан',
|
|
'Aşgabat (Merkezi diwany):': 'Ашхабад (Merkezi diwany):'
|
|
}[string];
|
|
}
|
|
|
|
function $_ID(id) {
|
|
return document.getElementById(id)
|
|
}
|
|
|
|
function removeByClassName(className) {
|
|
Array.from(document.getElementsByClassName(className)).forEach(item => item.remove())
|
|
}
|
|
|
|
function baseUrl() {
|
|
return 'https://test.webulgam.com';
|
|
}
|
|
|
|
function getData(url = '') {
|
|
return fetch(baseUrl() + url, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Accept': 'application/json'
|
|
}
|
|
})
|
|
.then(response => response.json());
|
|
}
|
|
|
|
function getCurrentLang() {
|
|
return window.locale || 'tm';
|
|
}
|
|
|
|
function withLang(url) {
|
|
const sep = url.includes('?') ? '&' : '?';
|
|
return url + sep + 'lang=' + getCurrentLang();
|
|
}
|
|
|
|
function isHomepage() {
|
|
return location.pathname === '/';
|
|
}
|
|
|
|
function isCategoryPage() {
|
|
return location.pathname === '/page.html';
|
|
}
|
|
|
|
function isBannerPage() {
|
|
return location.pathname === '/banner.html';
|
|
}
|
|
|
|
function isMiniCategoryPage() {
|
|
return location.pathname === '/action.html';
|
|
}
|
|
|
|
function isNewsPage() {
|
|
return location.pathname === '/news.html';
|
|
}
|
|
|
|
function initializeBasicFunctions() {
|
|
|
|
}
|
|
|
|
function setTranslations() {
|
|
const pageURL = new URL(location);
|
|
window.locale = ! pageURL.searchParams.has('lang') || pageURL.searchParams.get('lang') !== 'ru' ? 'tm' : 'ru';
|
|
|
|
if (window.locale !== 'ru') {
|
|
return;
|
|
}
|
|
|
|
Array.from(document.getElementsByClassName('translate-text')).forEach(item => {
|
|
item.innerText = tr(item.innerText)
|
|
})
|
|
|
|
Array.from(document.getElementsByClassName('translate-placeholder')).forEach(item => {
|
|
item.placeholder = tr(item.placeholder)
|
|
})
|
|
}
|
|
|
|
function fetchPhoneNumbers()
|
|
{
|
|
getData('/api/v1/client/users/setting')
|
|
.then(response => {
|
|
if (! response.status) {
|
|
return;
|
|
}
|
|
|
|
removeByClassName('phone-loaders');
|
|
|
|
$_ID('fax-number').innerText = response.data.faxNumber
|
|
$_ID('phone-number').innerText = response.data.phoneNumber
|
|
$_ID('help-number').innerText = tr('Sorag-jogap merkezi:') + ' ' + response.data.helpNumber
|
|
$_ID('year-logo').src = baseUrl() + response.data.logoR;
|
|
|
|
// second alignment of phone numbers
|
|
if (isHomepage()) {
|
|
$_ID('fax-number-second').innerText = response.data.faxNumber
|
|
$_ID('phone-number-second').innerText = response.data.phoneNumber
|
|
$_ID('help-number-second').innerText = tr('Sorag-jogap merkezi:') + ' ' + response.data.helpNumber
|
|
}
|
|
|
|
// Footer phone numbers
|
|
$_ID('footer-phone-number').innerText = response.data.phoneNumber
|
|
$_ID('footer-fax-number').innerText = response.data.faxNumber
|
|
})
|
|
}
|
|
|
|
async function fetchMenuItems() {
|
|
const container = $_ID('menu-items-container')
|
|
const sideBarMenuItems = $_ID('sidebar-menu-items')
|
|
|
|
const response = await getData(withLang('/api/v1/client/users/categories'))
|
|
|
|
response.data.forEach(menuItem => {
|
|
let subcategoriesTemplate = '';
|
|
|
|
if (menuItem.subCategories && menuItem.subCategories.length > 0 ) {
|
|
menuItem.subCategories.forEach(subcategory => {
|
|
if (subcategory.id && subcategory.name) {
|
|
subcategoriesTemplate += `
|
|
<li>
|
|
<a class="bg-trasparent lg:bg-white" href="${
|
|
'/page.html?id=' + subcategory.id + '&lang=' + getCurrentLang()
|
|
}">
|
|
${subcategory.name}
|
|
</a>
|
|
</li>
|
|
`;
|
|
}
|
|
})
|
|
}
|
|
|
|
const categoryName = (menuItem.name || '').toUpperCase()
|
|
|
|
container.insertAdjacentHTML('beforeend', `
|
|
<div class="dropdown" style="z-index:1000">
|
|
<button class="dropbtn flex items-center">
|
|
${categoryName}
|
|
${
|
|
subcategoriesTemplate !== ''
|
|
? '<img class="w-4 h-4" src="/images/arrow-down.svg" alt="">'
|
|
: ''
|
|
}
|
|
</button>
|
|
<div class="dropdown-content">
|
|
${subcategoriesTemplate}
|
|
</div>
|
|
</div>
|
|
`)
|
|
|
|
sideBarMenuItems.insertAdjacentHTML('beforeend', `
|
|
${
|
|
subcategoriesTemplate === ''
|
|
? `<li><a>${categoryName}</a></li>`
|
|
: `
|
|
<li>
|
|
<details class="w-[250px]">
|
|
<summary>${categoryName}</summary>
|
|
<ul>
|
|
${subcategoriesTemplate}
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
`
|
|
}
|
|
`)
|
|
})
|
|
}
|
|
|
|
async function fetchSliders() {
|
|
const imageSliderContainer = $_ID('slider-images-container')
|
|
const track = imageSliderContainer && imageSliderContainer.querySelector('.slider-track')
|
|
|
|
if (!track) return
|
|
|
|
const response = await getData('/api/v1/client/users/banners')
|
|
|
|
removeByClassName('homepage-slider-loader')
|
|
|
|
response.data.banners.forEach(slider => {
|
|
track.insertAdjacentHTML('beforeend', `
|
|
<div class="slider-slide">
|
|
<a href="${
|
|
slider.id
|
|
? `/banner.html?id=${slider.id}` + '&lang=' + getCurrentLang()
|
|
: ''
|
|
}">
|
|
<img
|
|
src="${baseUrl() + slider.imagePath}"
|
|
class="mx-auto w-full cursor-pointer" alt="slider"
|
|
>
|
|
</a>
|
|
</div>
|
|
`)
|
|
})
|
|
|
|
initializeMainSlider()
|
|
}
|
|
|
|
async function fetchMiniSliders() {
|
|
removeByClassName('minislider-loader')
|
|
}
|
|
|
|
async function fetchMiniCategories() {
|
|
const miniCategoryContainer = $_ID('mini-category-content-container')
|
|
|
|
const response = await getData(withLang('/api/v1/client/users/static'))
|
|
|
|
removeByClassName('mini-categories-loader')
|
|
|
|
response.data.statics.forEach(category => {
|
|
miniCategoryContainer.insertAdjacentHTML('beforeend', `
|
|
<a href="/action.html?id=${category.id}&lang=${getCurrentLang()}">
|
|
<div class="bg-gray-100 flex flex-1 flex-col items-center gap-3 py-7 px-3 mt-2 rounded-md">
|
|
<img src="${baseUrl() + category.logo}" class="w-16 h-16" alt="..." loading="lazy">
|
|
<h1 class="text-gray-700 uppercase text-center">${category.title}</h1>
|
|
</div>
|
|
</a>
|
|
`)
|
|
})
|
|
}
|
|
|
|
async function fetchCurrencies() {
|
|
const currencyTable = $_ID('currency-table')
|
|
const response = await getData(withLang('/api/v1/client/users/currency'))
|
|
|
|
removeByClassName('currency-table-loader')
|
|
currencyTable.innerHTML = response.data.content;
|
|
currencyTable.querySelector('table').classList.add('table-auto', 'bg-gray-500', 'text-sm', 'text-white', 'w-full')
|
|
|
|
Array.from(currencyTable.getElementsByTagName('th')).forEach(item => {
|
|
item.classList.add('p-2')
|
|
})
|
|
|
|
Array.from(currencyTable.getElementsByTagName('td')).forEach(item => {
|
|
item.classList.add('p-2')
|
|
|
|
if (item.hasAttribute('colwidth') && item.getAttribute('colwidth') !== '' || item.getAttribute('colwidth') !== null) {
|
|
item.setAttribute('style', `width: ${item.getAttribute('colwidth')}px`);
|
|
}
|
|
})
|
|
|
|
$_ID('currency-message-container').innerHTML = response.data.title;
|
|
}
|
|
|
|
async function fetchNews() {
|
|
const newsContainer = $_ID('news-content-container')
|
|
const response = await getData(withLang('/api/v1/client/users/news?limit=6&page=1'))
|
|
|
|
removeByClassName('news-loaders')
|
|
response.data.news.forEach(news => {
|
|
newsContainer.insertAdjacentHTML('beforeend', `
|
|
<a href="news.html?id=${news.id}&lang=${getCurrentLang()}">
|
|
<div class="flex flex-col px-3 mt-3">
|
|
<div class="h-60">
|
|
<img src="${baseUrl() + news.imagePath}" class="news-img-size" alt="..." loading="lazy">
|
|
</div>
|
|
<h1 class="text-base text-gray-800 mt-2 py-2 px-1 text-center">${news.title}</h1>
|
|
</div>
|
|
</a>
|
|
`)
|
|
})
|
|
}
|
|
|
|
async function fetchSubCategory() {
|
|
const pageURL = new URL(location);
|
|
|
|
if (! pageURL.searchParams.has('id')) {
|
|
return;
|
|
}
|
|
|
|
const pageContent = $_ID('page-content');
|
|
|
|
const response = await getData(withLang('/api/v1/client/users/sub-categories/' + pageURL.searchParams.get('id')))
|
|
|
|
removeByClassName('page-content-loader')
|
|
|
|
pageContent.innerHTML = `
|
|
<h1 id="page-title" class="uppercase mt-5 mb-5 text-center text-lg green-color text-bold">
|
|
${response.data.name}
|
|
</h1>
|
|
|
|
<div>
|
|
${response.data.content}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
async function fetchBannerContent() {
|
|
const pageURL = new URL(location);
|
|
|
|
if (! pageURL.searchParams.has('id')) {
|
|
return;
|
|
}
|
|
|
|
const pageContent = $_ID('page-content');
|
|
|
|
const response = await getData(withLang('/api/v1/client/users/banners/' + pageURL.searchParams.get('id')))
|
|
const banner = response.data
|
|
|
|
removeByClassName('page-content-loader')
|
|
|
|
if (! banner || ! banner.id) {
|
|
return;
|
|
}
|
|
|
|
pageContent.innerHTML = `
|
|
<h1 id="page-title" class="uppercase mt-5 mb-5 text-center text-lg green-color text-bold">
|
|
${banner.title}
|
|
</h1>
|
|
|
|
<div>
|
|
<img src="${baseUrl() + banner.imagePath}" class="w-full">
|
|
</div>
|
|
|
|
<div>
|
|
${banner.content || ''}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
async function fetchMiniCategory() {
|
|
const pageURL = new URL(location);
|
|
|
|
if (! pageURL.searchParams.has('id')) {
|
|
return;
|
|
}
|
|
|
|
const pageContent = $_ID('page-content');
|
|
|
|
const response = await getData(withLang('/api/v1/client/users/static/' + pageURL.searchParams.get('id')))
|
|
|
|
removeByClassName('page-content-loader')
|
|
|
|
pageContent.innerHTML = `
|
|
<h1 id="page-title" class="uppercase mt-5 mb-5 text-center text-lg green-color text-bold">
|
|
${response.data.title}
|
|
</h1>
|
|
|
|
<div>
|
|
${response.data.content || ''}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
async function fetchNewsContent() {
|
|
const pageURL = new URL(location);
|
|
|
|
if (! pageURL.searchParams.has('id')) {
|
|
return;
|
|
}
|
|
|
|
const pageContent = $_ID('page-content');
|
|
|
|
const response = await getData(withLang('/api/v1/client/users/news/' + pageURL.searchParams.get('id')))
|
|
|
|
removeByClassName('page-content-loader')
|
|
|
|
pageContent.innerHTML = `
|
|
<h1 id="page-title" class="uppercase mt-5 mb-5 text-center text-lg green-color text-bold">
|
|
${response.data.title}
|
|
</h1>
|
|
|
|
<div class="mb-5">
|
|
<img class="w-full max-h-[600px] object-contain" src="${baseUrl() + response.data.imagePath}">
|
|
</div>
|
|
|
|
<div>
|
|
<p class="mb-2">
|
|
${ new Date(response.data.dateRelease).toLocaleDateString('en-GB').replace(/\//g, '.') + 'ý' }
|
|
</p>
|
|
|
|
${response.data.content || ''}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', event => {
|
|
initializeBasicFunctions()
|
|
setTranslations()
|
|
fetchPhoneNumbers()
|
|
fetchMenuItems()
|
|
|
|
if (isHomepage()) {
|
|
fetchSliders()
|
|
fetchCurrencies()
|
|
fetchMiniSliders()
|
|
fetchNews()
|
|
}
|
|
|
|
if (isCategoryPage()) {
|
|
fetchSubCategory()
|
|
}
|
|
|
|
if (isBannerPage()) {
|
|
fetchBannerContent()
|
|
}
|
|
|
|
if (isMiniCategoryPage()) {
|
|
fetchMiniCategory()
|
|
}
|
|
|
|
if (isNewsPage()) {
|
|
fetchNewsContent()
|
|
}
|
|
|
|
fetchMiniCategories()
|
|
})
|