Files
2026-04-27 23:13:18 +02:00

160 lines
5.2 KiB
JavaScript

jQuery(function ($) {
const toggleText = 'Zwiń';
$('body').on('click', '.acc-tile-btn', function (e) {
e.preventDefault();
const $btn = $(this);
const $box = $btn.closest('.acc-tile-box');
const $content = $box.find('.acc-tile-data').first();
const $text = $btn.find('.elementor-button-text');
const defaultText = $btn.data('default-text') || $text.text();
if (!$btn.data('default-text')) {
$btn.data('default-text', defaultText);
}
const isOpen = $content.hasClass('active');
// Zamykamy wszystkie inne
$('.acc-tile-box').not($box).each(function () {
const $otherBox = $(this);
const $otherBtn = $otherBox.find('.acc-tile-btn').first();
const $otherContent = $otherBox.find('.acc-tile-data').first();
const $otherText = $otherBtn.find('.elementor-button-text');
const otherDefaultText = $otherBtn.data('default-text');
$otherContent.removeClass('active').slideUp();
$otherBtn.removeClass('active');
$otherBox.removeClass('active');
if (otherDefaultText) {
$otherText.text(otherDefaultText);
}
});
// Zmieniamy stan aktualnego
if (isOpen) {
$content.removeClass('active').slideUp();
$btn.removeClass('active');
$box.removeClass('active');
$text.text(defaultText);
} else {
$content.addClass('active').slideDown();
$btn.addClass('active');
$box.addClass('active');
$text.text(toggleText);
}
});
// $('body').on('click', '.acc-big-tile-btn', function (e) {
// e.preventDefault();
// const $btn = $(this);
// const $text = $btn.find('.elementor-button-text');
// const defaultText = $btn.data('default-text') || $text.text();
// const $content = $('.acc-big-tile-data');
// if (!$btn.data('default-text')) {
// $btn.data('default-text', defaultText);
// }
// const isOpen = $content.hasClass('active');
// if (isOpen) {
// $content.removeClass('active').slideUp();
// $btn.removeClass('active');
// $text.text(defaultText);
// $('.acc-big-tile-img').slideUp();
// } else {
// $content.addClass('active').slideDown();
// $btn.addClass('active');
// $text.text(toggleText);
// $('.acc-big-tile-img').slideDown();
// }
// });
$('body').on('click', '.acc-big-tile-btn', function (e) {
e.preventDefault();
const $btn = $(this);
const $text = $btn.find('.elementor-button-text');
const defaultText = $btn.data('default-text') || $text.text();
const $content = $('.acc-big-tile-data');
const $img = $('.acc-big-tile-img');
if (!$btn.data('default-text')) {
$btn.data('default-text', defaultText);
}
if (!$img.data('initial-height')) {
$img.data('initial-height', $img.outerHeight());
$img.height($img.outerHeight());
}
const initialHeight = $img.data('initial-height');
const isOpen = $content.hasClass('active');
if (isOpen) {
$content.removeClass('active').stop(true, true).slideUp(400);
$btn.removeClass('active');
$text.text(defaultText);
$img.stop(true, true).animate({
height: initialHeight
}, 400);
} else {
const targetHeight = $img.parent().outerHeight() + $content.outerHeight(true);
$content.addClass('active').stop(true, true).slideDown(400);
$btn.addClass('active');
$text.text(toggleText);
$img.stop(true, true).animate({
height: targetHeight + 16
}, 400);
}
});
// $('body').on('click', '.acc-big-tile-btn', function (e) {
// e.preventDefault();
// const $btn = $(this);
// const $text = $btn.find('.elementor-button-text');
// const defaultText = $btn.data('default-text') || $text.text();
// const $content = $('.acc-big-tile-data');
// const $img = $('.acc-big-tile-img');
// if (!$btn.data('default-text')) {
// $btn.data('default-text', defaultText);
// }
// if (!$img.data('initial-height')) {
// $img.data('initial-height', $img.outerHeight());
// $img.height($img.outerHeight());
// }
// const initialHeight = $img.data('initial-height');
// const isOpen = $content.hasClass('active');
// if (isOpen) {
// $content.removeClass('active').slideUp();
// $btn.removeClass('active');
// $text.text(defaultText);
// $img.stop(true, true).animate({
// height: initialHeight
// }, 400);
// } else {
// $content.addClass('active').slideDown(400, function () {
// const targetHeight = $img.parent().outerHeight();
// $img.stop(true, true).animate({
// height: targetHeight
// }, 400);
// });
// $btn.addClass('active');
// $text.text(toggleText);
// }
// });
});