<!--TCD019--><script src="https://cdn.jsdelivr.net/npm/jquery-touchswipe@1.6.19/jquery.touchSwipe.min.js"></script>
<script>
$(document).ready(function(){
let next = '.tc-next';
let prev = '.tc-prev';
let pagination = '#bullet';
let carousel = true;
let slides = '#rec510853759, #rec510854132';
let screens = [
{ min: 0, max: 480, active: true },
{ min: 480, max: 640, active: true },
{ min: 640, max: 960, active: true },
{ min: 960, max: 1200, active: true },
{ min: 1200, max: 10000, active: true },
];
let debug = false;
let script = '[TICODE-SLIDER]: ';
let active = true;
let arBlocks = slides.split(',');
let current = 0;
init();
$(next).click(function() {
slideNext();
});
$(prev).click(function() {
slidePrev();
});
$(document).on('click', '[href*="' + pagination + '"]', function (event) {
event.preventDefault();
if (false === active) return null;
let index = parseInt($(this).attr('href').replace(pagination, ''), 10);
if (!isNaN(index)) {
current = index - 1;
slide(current);
}
});
$(slides).swipe({
swipeRight: function(event, direction, distance, duration, fingerCount) {
slidePrev();
},
swipeLeft: function(event, direction, distance, duration, fingerCount) {
slideNext();
},
threshold:75
});
function init() {
log('Скрипт запущен');
checkScreen();
if (false === active) return null;
let slideNumber = getSlideNumberFromHash();
if (slideNumber !== null) {
current = slideNumber - 1;
}
setTimeout(function () {
reloadAnimation(current);
hideAllSlides();
showSlide(current);
updateHash(current + 1);
}, 100);
}
function checkScreen() {
let width = $(window).width();
screens.forEach(function (item, i, arr) {
if (width > item.min && width <= item.max) active = item.active;
});
}
function slideNext() {
if (false === active) return null;
if (current + 1 === arBlocks.length && carousel === true) {
current = -1;
}
if (current + 1 < arBlocks.length) {
current++;
slide(current);
}
}
function slidePrev() {
if (false === active) return null;
if (current === 0 && carousel === true) {
current = arBlocks.length;
}
if (current - 1 >= 0) {
current--;
slide(current);
}
}
function slide(n) {
setTimeout(function () {
reloadAnimation(n);
hideAllSlides();
showSlide(n);
updateHash(n + 1);
}, 100);
}
function hideAllSlides() {
arBlocks.forEach(function (item, i, arr) {
hide($(item));
});
}
function showSlide(n) {
show($(arBlocks[n]));
if ("y" === window.lazy) {
t_lazyload_update();
}
if (typeof t_slds_updateSlider != "undefined") {
let idPart = arBlocks[n].replace('#rec', '');
t_slds_updateSlider(idPart);
}
}
function reloadAnimation(n) {
$current = $(arBlocks[n]);
arBlocks.forEach(function (item, i, arr) {
$(item).find('.t396__elem').each(function (i, e) {
$(this).removeClass('t-sbs-anim_started t-animate_started');
});
});
$current.find('.t396__elem').each(function (i, e) {
$(this).addClass('t-sbs-anim_started t-animate_started');
});
arBlocks.forEach(function (item, i, arr) {
$(item).find('.t396__elem[data-animate-style]').each(function (i, e) {
$(this).removeClass('t-animate_started');
});
});
setTimeout(function () {
$current.find('.t396__elem[data-animate-style]').each(function (i, e) {
$(this).addClass('t-animate_started');
});
}, 100);
}
function hide($element) {
$element.css({
'display': 'none'
});
log('Скрыт элемент ticode' + $element.attr('id'));
}
function show($element) {
$element.css({
'display': 'block'
});
log('Показан элемент ticode' + $element.attr('id'));
}
function log(message) {
if (debug) console.log(script + message);
}
function getSlideNumberFromHash() {
let hash = window.location.hash;
if (hash && hash.indexOf('#bullet') === 0) {
let slideNumber = parseInt(hash.replace('#bullet', ''), 10);
if (!isNaN(slideNumber) && slideNumber >= 1 && slideNumber <= arBlocks.length) {
return slideNumber;
}
}
return null;
}
function updateHash(slideNumber) {
var newHash = '#bullet' + slideNumber;
window.location.hash = newHash;
setTimeout(function() {
history.replaceState({}, document.title, window.location.pathname + window.location.search);
}, 500);
}
});
</script>
<style>
.tc-next { cursor: pointer; }
.tc-prev { cursor: pointer; }
</style>