Files
Web_Chaloupky/assets/js/v1.05_app.js
2024-07-07 22:32:04 +02:00

806 lines
21 KiB
JavaScript

$('a[href*="#"]')
// Remove links that don't actually link to anything
.not('[href="#"]')
.not('[href="#0"]')
.click(function(event) {
// On-page links
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
&&
location.hostname == this.hostname
) {
// Figure out element to scroll to
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
// Does a scroll target exist?
if (target.length) {
// Only prevent default if animation is actually gonna happen
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top - 80
}, 800, function() {
// Callback after animation
// Must change focus!
var $target = $(target);
$target.focus();
if ($target.is(":focus")) { // Checking if the target was focused
return false;
} else {
$target.attr('tabindex','-1'); // Adding tabindex for elements not focusable
$target.focus(); // Set focus again
};
});
}
}
});
init();
function init() {
let state = 0;
$('.js-prev-slide').click(function() {
if(state - 1 == -1){state = 2;}else{state = state - 1;}
swiper(state,0);
});
$('.js-next-slide').click(function() {
if(state + 1 == 3){state = 0;}else{state = state + 1;}
swiper(state,1);
});
$('.js-menu-object').click(function() {
closeSequence($('body').find('.section--block' + $(this).attr('href')));
});
$('.js-menu-detail').click(function() {
menuControl($('body').find('.section--block' + $(this).attr('href')), "detail");
});
$('.js-menu-gallery').click(function() {
menuControl($('body').find('.section--block' + $(this).attr('href')), "gallery");
});
$('.js-menu-price').click(function() {
menuControl($('body').find('.section--block' + $(this).attr('href')), "price");
});
$('.js-left-open').click(function() {
let position;
if (screen.width > 1200){position = 50;}else{position = 0;}
if($(this).closest('.section').hasClass('section--switch')){
$(this).closest('.section').find('.section__left').css('left',position + '%');
}else{
$(this).closest('.section').find('.section__left').css('left','0%');
}
});
$('.js-left-close').click(function() {
let position1;
let position2;
if (screen.width > 1200){position1 = 0;position2 = -50;}else{position1 = -100;position2 = -100;}
if($(this).closest('.section').hasClass('section--switch')){
$(this).closest('.section').find('.section__left').css('left',position1 + '%');
}else{
$(this).closest('.section').find('.section__left').css('left',position2 + '%');
}
});
$('.js-gallery-open').click(function() {
const x = $(this).closest('.section').find('.section__gallery');
x.addClass('is-open');
if(!x.hasClass('loaded')){loadGallery(this,x.attr('data-object'),x.attr('data-items'));}
});
$('.js-gallery-close').click(function() {
$(this).closest('.section').find('.section__gallery').removeClass('is-open');
});
$('.js-right-open').click(function() {
let position;
if (screen.width > 1200){position = 50;}else{position = 0;}
if($(this).closest('.section').hasClass('section--switch')){
$(this).closest('.section').find('.section__right').css('left',position + '%');
}else{
$(this).closest('.section').find('.section__right').css('left','0%');
}
});
$('.js-right-close').click(function() {
let position;
if (screen.width > 1200){position = 50}else{position = 100;}
if($(this).closest('.section').hasClass('section--switch')){
$(this).closest('.section').find('.section__right').css('left','100%');
}else{
$(this).closest('.section').find('.section__right').css('left',position + '%');
}
});
$('.js-preview-close').click(function() {
$('body').removeClass('noscroll');
$('body').find('.section--preview').removeClass('is-open');
});
$('.js-gdpr-open').click(function() {
$('body').removeClass('noscroll');
$('body').find('.section--gdpr').addClass('is-open');
});
$('.js-gdpr-close').click(function() {
$('body').removeClass('noscroll');
$('body').find('.section--gdpr').removeClass('is-open');
});
$('.js-preview-prev').click(function() {
let data = $(this).closest('.section--preview');
let x = Number(data.attr('data-object'));
let y = Number(data.attr('data-item'));
let z = Number(data.attr('data-items'));
if (window.innerWidth > window.innerHeight) {
galleryControl(x,0,y,z);
} else {
galleryControl(x,1,y,z);
}
});
$('.js-preview-next').click(function() {
let data = $(this).closest('.section--preview');
let x = Number(data.attr('data-object'));
let y = Number(data.attr('data-item'));
let z = Number(data.attr('data-items'));
if (window.innerWidth > window.innerHeight) {
galleryControl(x,1,y,z);
} else {
galleryControl(x,0,y,z);
}
});
$('.js-menu-button').click(function() {
if($(this).hasClass('is-active')){
$(this).removeClass('is-active');
$('body').removeClass('noscroll');
$('body').find('.header').removeClass('is-open');
}else{
$(this).addClass('is-active');
$('body').addClass('noscroll');
$('body').find('.header').addClass('is-open');
}
});
$('.js-menu-close').click(function() {
$('body').find('.header').removeClass('is-open');
$('body').find('.js-menu-button').removeClass('is-active');
$('body').removeClass('noscroll');
});
}
function swiper(e,f) {
const a = $('.js-slide-one');
const b = $('.js-slide-two');
const c = $('.js-slide-three');
if (e == 1) {
if (f == 1) {
$(a).css('zIndex','1');
$(c).css('zIndex','-1');
} else {
$(a).css('zIndex','-1');
$(c).css('zIndex','1');
}
$(b).css('zIndex','1');
$(a).css('left','-100%');
$(b).css('left','0%');
$(c).css('left','100%');
} else if (e == 2) {
if (f == 1) {
$(b).css('zIndex','1');
$(a).css('zIndex','-1');
} else {
$(b).css('zIndex','-1');
$(a).css('zIndex','1');
}
$(c).css('zIndex','1');
$(a).css('left','100%');
$(b).css('left','-100%');
$(c).css('left','0%');
} else {
if (f == 1) {
$(c).css('zIndex','1');
$(b).css('zIndex','-1');
} else {
$(c).css('zIndex','-1');
$(b).css('zIndex','1');
}
$(a).css('zIndex','1');
$(a).css('left','0%');
$(b).css('left','100%');
$(c).css('left','-100%');
}
}
function loadGallery(item,object,maxItems){
let imageUrls = [];
const loadImage = src =>
new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(img);
img.onerror = reject;
img.src = src;
})
;
switch(Number(object)) {
case 0:
imageUrls = [
"img/gallery/statek/thumbs/1.webp",
"img/gallery/statek/thumbs/2.webp",
"img/gallery/statek/thumbs/3.webp",
"img/gallery/statek/thumbs/4.webp",
"img/gallery/statek/thumbs/5.webp",
"img/gallery/statek/thumbs/6n.webp",
"img/gallery/statek/thumbs/7.webp",
"img/gallery/statek/thumbs/30.webp",
"img/gallery/statek/thumbs/8.webp",
"img/gallery/statek/thumbs/9.webp",
"img/gallery/statek/thumbs/10.webp",
"img/gallery/statek/thumbs/11.webp",
"img/gallery/statek/thumbs/12.webp",
"img/gallery/statek/thumbs/13.webp",
"img/gallery/statek/thumbs/14.webp",
"img/gallery/statek/thumbs/15.webp",
"img/gallery/statek/thumbs/16.webp",
"img/gallery/statek/thumbs/17.webp",
"img/gallery/statek/thumbs/18.webp",
"img/gallery/statek/thumbs/19.webp",
"img/gallery/statek/thumbs/20.webp",
"img/gallery/statek/thumbs/21.webp",
"img/gallery/statek/thumbs/22.webp",
"img/gallery/statek/thumbs/23.webp",
"img/gallery/statek/thumbs/24.webp",
"img/gallery/statek/thumbs/w9n.webp",
"img/gallery/statek/thumbs/26.webp",
"img/gallery/statek/thumbs/27n.webp",
"img/gallery/statek/thumbs/28n.webp",
"img/gallery/statek/thumbs/29.webp",
"img/gallery/statek/thumbs/31.webp",
"img/gallery/statek/thumbs/32.webp"
];
break;
case 1:
imageUrls = [
"img/gallery/penzion/thumbs/1.webp",
"img/gallery/penzion/thumbs/2.webp",
"img/gallery/penzion/thumbs/3.webp",
"img/gallery/penzion/thumbs/4.webp",
"img/gallery/penzion/thumbs/32.webp",
"img/gallery/penzion/thumbs/25.webp",
"img/gallery/penzion/thumbs/5.webp",
"img/gallery/penzion/thumbs/6.webp",
"img/gallery/penzion/thumbs/7.webp",
"img/gallery/penzion/thumbs/8.webp",
"img/gallery/penzion/thumbs/9.webp",
"img/gallery/penzion/thumbs/10.webp",
"img/gallery/penzion/thumbs/11.webp",
"img/gallery/penzion/thumbs/12.webp",
"img/gallery/penzion/thumbs/13.webp",
"img/gallery/penzion/thumbs/14.webp",
"img/gallery/penzion/thumbs/15.webp",
"img/gallery/penzion/thumbs/16.webp",
"img/gallery/penzion/thumbs/17.webp",
"img/gallery/penzion/thumbs/18.webp",
"img/gallery/penzion/thumbs/19.webp",
"img/gallery/penzion/thumbs/20.webp",
"img/gallery/penzion/thumbs/21.webp",
"img/gallery/penzion/thumbs/22.webp",
"img/gallery/penzion/thumbs/23.webp",
"img/gallery/penzion/thumbs/24.webp",
"img/gallery/penzion/thumbs/26.webp",
"img/gallery/penzion/thumbs/27.webp",
"img/gallery/penzion/thumbs/28.webp",
"img/gallery/penzion/thumbs/29.webp",
"img/gallery/penzion/thumbs/30.webp",
"img/gallery/penzion/thumbs/31.webp"
];
break;
case 2:
imageUrls = [
"img/gallery/chata/thumbs/1.webp",
"img/gallery/chata/thumbs/2.webp",
"img/gallery/chata/thumbs/3.webp",
"img/gallery/chata/thumbs/4.webp",
"img/gallery/chata/thumbs/5.webp",
"img/gallery/chata/thumbs/6.webp",
"img/gallery/chata/thumbs/7.webp",
"img/gallery/chata/thumbs/8.webp",
"img/gallery/chata/thumbs/9.webp",
"img/gallery/chata/thumbs/10.webp",
"img/gallery/chata/thumbs/11.webp",
"img/gallery/chata/thumbs/12.webp",
"img/gallery/chata/thumbs/13.webp",
"img/gallery/chata/thumbs/14.webp",
"img/gallery/chata/thumbs/15.webp",
"img/gallery/chata/thumbs/16.webp",
"img/gallery/chata/thumbs/17.webp",
"img/gallery/chata/thumbs/18.webp",
"img/gallery/chata/thumbs/19.webp",
"img/gallery/chata/thumbs/20.webp",
"img/gallery/chata/thumbs/21.webp",
"img/gallery/chata/thumbs/22.webp",
"img/gallery/chata/thumbs/23.webp",
"img/gallery/chata/thumbs/24.webp",
"img/gallery/chata/thumbs/25.webp",
"img/gallery/chata/thumbs/26.webp",
"img/gallery/chata/thumbs/27.webp",
"img/gallery/chata/thumbs/28.webp"
];
break;
case 3:
imageUrls = [
"img/gallery/statek/thumbs/w6.webp",
"img/gallery/statek/thumbs/w11.webp",
"img/gallery/statek/thumbs/w2.webp",
"img/gallery/statek/thumbs/6n.webp",
"img/gallery/statek/thumbs/w3.webp",
"img/gallery/statek/thumbs/3.webp",
"img/gallery/statek/thumbs/9.webp",
"img/gallery/statek/thumbs/8.webp",
"img/gallery/statek/thumbs/7.webp",
"img/gallery/statek/thumbs/11.webp",
"img/gallery/statek/thumbs/w5.webp",
"img/gallery/statek/thumbs/w7.webp",
"img/gallery/statek/thumbs/28n.webp",
"img/gallery/statek/thumbs/w9n.webp",
"img/gallery/statek/thumbs/w12.webp",
"img/gallery/statek/thumbs/25n.webp",
"img/gallery/statek/thumbs/26.webp",
"img/gallery/statek/thumbs/27n.webp",
"img/gallery/statek/thumbs/w8.webp",
"img/gallery/statek/thumbs/w20.webp"
];
}
Promise.all(imageUrls.map(loadImage)).then(images => {
let count = 1;
images.forEach((image, i) =>{
$(item).closest('.section').find('.gallery').append($('<div class="gallery__item js-gallery-item" data-order="' + count + '"></div>').append(image));
if(count == maxItems){
$(item).closest('.section').find('.section__gallery').addClass('loaded');
$('.js-gallery-item').click(function() {
let z,q,v;
let x = $('body').find('.section--preview');
let y = Number($(this).attr('data-order'));
let w = Number($(item).closest('.section').find('.section__gallery').attr('data-items'));
let c = $(this).closest('.section').attr('id');
if(c == "statek"){z = 0;}else if(c == "penzion"){z = 1;}else if(c == "chata"){z = 2;}else{z = 3;}
$('body').addClass('noscroll');
x.attr('data-object',z);
x.attr('data-item',y);
x.attr('data-items',w);
q = $(this).find('img').attr('src').split("/");
if(c=="events"){v = "statek"}else{v = c;}
x.find('img').attr('src','img/gallery/' + v + '/' + q[4]);
x.addClass('is-open');
});
}
count = count + 1;
});
}
);
}
function galleryControl(e,f,g,h) {
let object;
let next = loopControl(g, f, h);
switch(e) {
case 0:
object = "statek";
break;
case 1:
object = "penzion";
break;
case 2:
object = "chata";
break;
case 3:
object = "statek";
}
$('body').find('.section--preview').attr('data-item',next);
if(e==0){
switch(next) {
case 1:
next = "1";
break;
case 2:
next = "2";
break;
case 3:
next = "3";
break;
case 4:
next = "4";
break;
case 5:
next = "5";
break;
case 6:
next = "6n";
break;
case 7:
next = "7";
break;
case 8:
next = "30";
break;
case 9:
next = "8";
break;
case 10:
next = "9";
break;
case 11:
next = "10";
break;
case 12:
next = "11";
break;
case 13:
next = "12";
break;
case 14:
next = "13";
break;
case 15:
next = "14";
break;
case 16:
next = "15";
break;
case 17:
next = "16";
break;
case 18:
next = "17";
break;
case 19:
next = "18";
break;
case 20:
next = "19";
break;
case 21:
next = "20";
break;
case 22:
next = "21";
break;
case 23:
next = "22";
break;
case 24:
next = "23";
break;
case 25:
next = "24";
break;
case 26:
next = "w9n";
break;
case 27:
next = "26";
break;
case 28:
next = "27";
break;
case 29:
next = "28";
break;
case 30:
next = "29";
break;
case 31:
next = "31";
break;
case 32:
next = "32";
}
}
if(e==1){
switch(next) {
case 1:
next = "1";
break;
case 2:
next = "2";
break;
case 3:
next = "3";
break;
case 4:
next = "4";
break;
case 5:
next = "32";
break;
case 6:
next = "25";
break;
case 7:
next = "5";
break;
case 8:
next = "6";
break;
case 9:
next = "7";
break;
case 10:
next = "8";
break;
case 11:
next = "9";
break;
case 12:
next = "10";
break;
case 13:
next = "11";
break;
case 14:
next = "12";
break;
case 15:
next = "13";
break;
case 16:
next = "14";
break;
case 17:
next = "15";
break;
case 18:
next = "16";
break;
case 19:
next = "17";
break;
case 20:
next = "18";
break;
case 21:
next = "19";
break;
case 22:
next = "20";
break;
case 23:
next = "21";
break;
case 24:
next = "22";
break;
case 25:
next = "23";
break;
case 26:
next = "24";
break;
case 27:
next = "26";
break;
case 28:
next = "27";
break;
case 29:
next = "28";
break;
case 30:
next = "29";
break;
case 31:
next = "30";
break;
case 32:
next = "31";
}
}
if(e==2){
switch(next) {
case 1:
next = "1";
break;
case 2:
next = "2";
break;
case 3:
next = "3";
break;
case 4:
next = "4";
break;
case 5:
next = "5";
break;
case 6:
next = "6";
break;
case 7:
next = "7";
break;
case 8:
next = "8";
break;
case 9:
next = "9";
break;
case 10:
next = "10";
break;
case 11:
next = "11";
break;
case 12:
next = "12";
break;
case 13:
next = "13";
break;
case 14:
next = "14";
break;
case 15:
next = "15";
break;
case 16:
next = "16";
break;
case 17:
next = "17";
break;
case 18:
next = "18";
break;
case 19:
next = "19";
break;
case 20:
next = "20";
break;
case 21:
next = "21";
break;
case 22:
next = "22";
break;
case 23:
next = "23";
break;
case 24:
next = "24";
break;
case 25:
next = "25";
break;
case 26:
next = "26";
break;
case 27:
next = "27";
break;
case 28:
next = "28";
}
}
if(e==3){
switch(next) {
case 1:
next = "w6";
break;
case 2:
next = "w11";
break;
case 3:
next = "w2";
break;
case 4:
next = "6n";
break;
case 5:
next = "w3";
break;
case 6:
next = "3";
break;
case 7:
next = "9";
break;
case 8:
next = "8";
break;
case 9:
next = "7";
break;
case 10:
next = "11";
break;
case 11:
next = "w5";
break;
case 12:
next = "w7";
break;
case 13:
next = "28n";
break;
case 14:
next = "w9n";
break;
case 15:
next = "w12";
break;
case 16:
next = "25n";
break;
case 17:
next = "26";
break;
case 18:
next = "27";
break;
case 19:
next = "w8";
break;
case 20:
next = "w20"
}
}
$('body').find('.section--preview').find('img').attr('src','img/gallery/' + object + '/' + next + '.webp');
}
function loopControl(e,f,g) {
if(f){if(0==e-1){e=g;}else{e=e-1;}}else{if(g+1==e+1){e=1;}else{e=e+1;}}return e;
}
function menuControl(e,f) {
let position;
if (screen.width > 1200){position = 50;}else{position = 0}
closeSequence(e);
if(f=="detail"){
if(e.hasClass('section--switch')){
e.find('.section__left').css('left',position+'%');
}else{
e.find('.section__left').css('left','0%');
}
}else if(f=="gallery"){
let x = e.find('.section__gallery');
x.addClass('is-open');
if(!x.hasClass('loaded')){loadGallery(e,x.attr('data-object'),x.attr('data-items'));}
}else{
if(e.hasClass('section--switch')){
e.find('.section__right').css('left',position+'%');
}else{
e.find('.section__right').css('left','0%');
}
}
}
function closeSequence(e) {
let position1;
let position2;
let position3;
let position4;
if (screen.width > 1200){position1 = 0;position2 = 100;position3 = -50;position4 = 50;}else{position1 = -100;position2 = 100;position3 = -100;position4 = 100;}
if($('body').find('.header').hasClass('is-open')){
$('body').removeClass('noscroll');
$('body').find('.header').removeClass('is-open');
$('body').find('.js-menu-button').removeClass('is-active');
}
if(e.hasClass('section--switch')){
e.find('.section__left').css('left',position1+'%');
e.find('.section__right').css('left',position2+'%');
}else{
e.find('.section__left').css('left',position3+'%');
e.find('.section__right').css('left',position4+'%');
}
e.find('.section__gallery').removeClass('is-open');
}