(function($){
'use strict';
let lenis=null;
const DEBUG_TURNSTILE=false;
window.addEventListener('DiadaoWpSdkStarted', event=> {
startScript();
});
function handleMainMenu(open_it){
if(open_it){
jQuery('body').addClass('mainmenu-opened');
jQuery('#mainmenu-embruns-panel').addClass('opened');
if(lenis!==null) lenis.stop();
}else{
jQuery('body').removeClass('mainmenu-opened');
jQuery('#mainmenu-embruns-panel').removeClass('opened');
if(lenis!==null) lenis.start();
}}
function startScript(){
if(document.querySelector('body').classList.contains('device-desktop')){
lenis=new Lenis();
}
jQuery(document).on('click', '#mainmenu-embruns-trigger', function(e){
e.preventDefault();
console.log('open main menu');
handleMainMenu(true);
});
jQuery(document).on('click', '#mainmenu-embruns-close', function(e){
e.preventDefault();
console.log('close on click');
handleMainMenu(false);
});
jQuery(document).on('keydown', function(e){
if(event.key==="Escape"){
if(jQuery('#fullmovie').hasClass('show')){
e.preventDefault();
jQuery('#fullmovie .btn-close').trigger('click');
}else if(jQuery('body').hasClass('mainmenu-opened')){
e.preventDefault();
console.log('close on escape');
handleMainMenu(false);
}}
});
let minguest=0;
let minroom=0;
let minsdb=0;
let withanimal=-1;
const $roomcontainer=jQuery('.accomodationsrub__desktoplist');
const roommodedesktop=($roomcontainer.length > 0);
let $hiddenCurrentTargets;
let $shownCurrentTargets;
let $hiddenFutureTargets;
let $shownFutureTargets;
let containerOldHeight;
let containerFutureHeight;
let tblRooms=new Array();
jQuery('.encartroom').each((i,el)=> {
const $thisroom=jQuery(el);
const thisroomposition=$thisroom.position();
tblRooms.push({
el: $thisroom,
nbguest: parseInt($thisroom.attr('data-nbguest')),
nbroom: parseInt($thisroom.attr('data-nbroom')),
nbbathroom: parseInt($thisroom.attr('data-nbbathroom')),
animals: parseInt($thisroom.attr('data-animals')),
kept: true,
waskept: true,
fromtop: thisroomposition.top,
fromleft: thisroomposition.left,
fromwidth: getComputedStyle(el).width,
fromheight: getComputedStyle(el).height,
totop:0,
toleft:0,
towidth:0,
toheight:0
}
);
})
const nbrooms=tblRooms.length;
let roomsFilteredOnce=false;
jQuery(document).on('click', '.accomodationsrub__search__open', ()=> {
jQuery('.accomodationsrub__search').toggleClass('open');
if(!roomsFilteredOnce){
const $firstselect=jQuery('.accomodationsrub__search__select').eq(0);
if(!$firstselect.hasClass('open')) $firstselect.trigger('click');
}});
jQuery(document).on('click', '.accomodationsrub__search__close, .accomodationsrub__search__fixedbg, .accomodationsrub__search__validate', ()=> {
jQuery('.accomodationsrub__search').removeClass('open');
});
jQuery(document).on('click', '.accomodationsrub__search__select', (e)=> {
const $thisselect=jQuery(e.currentTarget);
if(jQuery(e.currentTarget).hasClass('open')){
jQuery('.accomodationsrub__search__select').removeClass('open');
}else{
jQuery('.accomodationsrub__search__select').removeClass('open');
jQuery(e.currentTarget).addClass('open');
}});
jQuery('body').on('click.closeHebergements', (e)=> {
if(!jQuery(e.target).hasClass('accomodationsrub__search__select')&&jQuery(e.target).closest('.accomodationsrub__search__select').length <=0){
jQuery('.accomodationsrub__search__select').removeClass('open');
}});
jQuery(document).on('click', '.accomodationsrub__search__nbguest .accomodationsrub__search__select__option', (e)=> {
const $thisoption=jQuery(e.currentTarget);
minguest=parseInt($thisoption.attr('data-nb'));
activateSelect($thisoption);
});
jQuery(document).on('click', '.accomodationsrub__search__nbroom .accomodationsrub__search__select__option', (e)=> {
const $thisoption=jQuery(e.currentTarget);
minroom=parseInt($thisoption.attr('data-nb'));
activateSelect($thisoption);
});
jQuery(document).on('click', '.accomodationsrub__search__nbsdb .accomodationsrub__search__select__option', (e)=> {
const $thisoption=jQuery(e.currentTarget);
minsdb=parseInt($thisoption.attr('data-nb'));
activateSelect($thisoption);
});
jQuery(document).on('click', '.accomodationsrub__search__animals .accomodationsrub__search__select__option', (e)=> {
const $thisoption=jQuery(e.currentTarget);
withanimal=parseInt($thisoption.attr('data-nb'));
activateSelect($thisoption);
});
jQuery(document).on('click', '.accomodationsrub__search__nbguest .accomodationsrub__search__select__close', (e)=> {
e.stopPropagation();
minguest=0;
clearSelect(jQuery(e.currentTarget).closest('.accomodationsrub__search__select'));
});
jQuery(document).on('click', '.accomodationsrub__search__nbroom .accomodationsrub__search__select__close', (e)=> {
e.stopPropagation();
minroom=0;
clearSelect(jQuery(e.currentTarget).closest('.accomodationsrub__search__select'));
});
jQuery(document).on('click', '.accomodationsrub__search__nbsdb .accomodationsrub__search__select__close', (e)=> {
e.stopPropagation();
minsdb=0;
clearSelect(jQuery(e.currentTarget).closest('.accomodationsrub__search__select'));
});
jQuery(document).on('click', '.accomodationsrub__search__animals .accomodationsrub__search__select__close', (e)=> {
e.stopPropagation();
withanimal=-1;
clearSelect(jQuery(e.currentTarget).closest('.accomodationsrub__search__select'));
});
function activateSelect($thisoption){
const $thisselect=$thisoption.closest('.accomodationsrub__search__select');
$thisselect.addClass('active');
$thisselect.find('.accomodationsrub__search__select__option').removeClass('active');
$thisoption.addClass('active');
$thisselect.find('.accomodationsrub__search__select__current').html($thisoption.html());
roomsFilteredOnce=true;
sortRooms();
}
function clearSelect($thisselect){
$thisselect.removeClass('active open');
$thisselect.find('.accomodationsrub__search__select__option').removeClass('active');
sortRooms();
}
function sortRooms(){
jQuery('.encartroom').removeClass('hideanim');
let lastkeptroom=0;
let i=0;
let nbtoshow=0;
$hiddenCurrentTargets=jQuery([]);
$shownCurrentTargets=jQuery([]);
$hiddenFutureTargets=jQuery([]);
$shownFutureTargets=jQuery([]);
let $toShowTargets=jQuery([]);
if(roommodedesktop){
jQuery('.encartroom').stop();
$roomcontainer.stop();
containerOldHeight=$roomcontainer.outerHeight();
}
for(i=0;i<nbrooms;i++){
const thisroom=tblRooms[i];
let roomiskept=true;
if(thisroom.nbguest < minguest) roomiskept=false;
if(thisroom.nbroom < minroom) roomiskept=false;
if(thisroom.nbbathroom < minsdb) roomiskept=false;
if(withanimal!==-1&&thisroom.animals!==withanimal) roomiskept=false;
if(!roomiskept){
thisroom.kept=false;
$hiddenFutureTargets=$hiddenFutureTargets.add(thisroom.el[0]);
}else{
thisroom.kept=true;
lastkeptroom=i;
$shownFutureTargets=$shownFutureTargets.add(thisroom.el[0]);
}
if(thisroom.waskept){
$shownCurrentTargets=$shownCurrentTargets.add(thisroom.el[0]);
}else{
$hiddenCurrentTargets=$hiddenCurrentTargets.add(thisroom.el[0]);
if(roomiskept){
$toShowTargets=$toShowTargets.add(thisroom.el[0]);
}}
const thisroomposition=thisroom.el.position();
thisroom.fromtop=thisroomposition.top;
thisroom.fromleft=thisroomposition.left;
thisroom.fromwidth=getComputedStyle(thisroom.el[0]).width;
thisroom.fromheight=getComputedStyle(thisroom.el[0]).height;
}
nbtoshow=$shownFutureTargets.length;
if(roommodedesktop){
$roomcontainer.stop();
containerOldHeight=$roomcontainer.outerHeight();
jQuery('.encartroom').css({
'position':'static', 'height':'', 'width':'', 'top':'', 'left':''
});
$shownFutureTargets.show();
$hiddenFutureTargets.hide();
jQuery('.encartroom--last').removeClass('encartroom--last');
tblRooms[lastkeptroom].el.addClass('encartroom--last');
$shownFutureTargets.each((i, e)=> {
const thisroom=tblRooms[jQuery(e).index()];
const thisroomposition=thisroom.el.position();
thisroom.totop=thisroomposition.top;
thisroom.toleft=thisroomposition.left;
thisroom.towidth=getComputedStyle(thisroom.el[0]).width;
thisroom.toheight=getComputedStyle(thisroom.el[0]).height;
});
$roomcontainer.css('height', '');
containerFutureHeight=$roomcontainer.outerHeight();
$roomcontainer.css('height', containerOldHeight);
$shownCurrentTargets.show();
$hiddenCurrentTargets.hide();
jQuery('.encartroom').each((i, e)=> {
const thisroom=tblRooms[i];
const fromPosition=jQuery(e).data('from-position');
thisroom.el.css({
position: 'absolute',
top: thisroom.fromtop,
left: thisroom.fromleft,
width: thisroom.fromwidth,
height: thisroom.fromheight
});
thisroom.waskept=thisroom.kept;
});
$hiddenFutureTargets.addClass('hideanim');
let nbanimated=0;
if(nbtoshow > 0){
jQuery('.noroom').slideUp("fast");
$shownFutureTargets.removeClass('hideanim').show().each((i,e)=> {
const thisroom=tblRooms[jQuery(e).index()];
thisroom.el.animate({
top: thisroom.totop,
left: thisroom.toleft,
width: thisroom.towidth,
height: thisroom.toheight
}, {
duration: 300,
complete: ()=> {
nbanimated++;
if(nbanimated>=nbtoshow){
$hiddenFutureTargets.css('display', 'none');
jQuery('.encartroom').css({'position':'static', 'height':'', 'width':'', 'top':'', 'left':''});
$roomcontainer.animate({
height: containerFutureHeight,
}, 200, ()=> {
$roomcontainer.css('height', '');
const st=window.pageYOffset||document.documentElement.scrollTop;
const containerScrollTop=$roomcontainer.offset().top;
const scrollTop=containerScrollTop - jQuery('#diadao-navbar').outerHeight();
if(st > scrollTop){
jQuery('html, body').animate({
scrollTop: scrollTop + 40,
}, 400);
}
jQuery(window).trigger('resize');
if(ScrollTrigger!==null) ScrollTrigger.refresh();
});
}}
});
});
}else{
jQuery('.noroom').slideDown("fast");
$roomcontainer.animate({
height: 0,
}, 200, ()=> {
const st=window.pageYOffset||document.documentElement.scrollTop;
const containerScrollTop=$roomcontainer.offset().top;
const scrollTop=containerScrollTop - jQuery('#diadao-navbar').outerHeight();
if(st > scrollTop){
jQuery('html, body').animate({
scrollTop: scrollTop - 40,
}, 400);
}
jQuery(window).trigger('resize');
if(ScrollTrigger!==null) ScrollTrigger.refresh();
});
}}else{
let currentroomindex=0;
const myswiper=jQuery('.accomodationsswiper')[0].swiper;
if(nbtoshow > 0){
jQuery('.noroom').slideUp("fast");
for(i=0;i<nbrooms;i++){
const thisroom=tblRooms[i];
if(thisroom.kept){
if(!thisroom.waskept){
myswiper.addSlide(currentroomindex, thisroom.el[0]);
}else{
}
currentroomindex++;
}else{
if(thisroom.waskept){
myswiper.removeSlide(currentroomindex);
}else{
}}
thisroom.waskept=thisroom.kept;
}}else{
jQuery('.noroom').slideDown("fast");
myswiper.removeAllSlides();
for(i=0;i<nbrooms;i++){
const thisroom=tblRooms[i];
thisroom.waskept=thisroom.kept;
}}
myswiper.update();
myswiper.slideTo(0);
jQuery(window).trigger('resize');
if(ScrollTrigger!==null) ScrollTrigger.refresh();
}};
function scrollToBookRoom(whichone){
if(typeof whichone!=='undefined'){
const $thisroombook=jQuery('.kwpb-diadao-room-detail[data-roomid="' + whichone + '"] .snippet-room-ctoutvert');
if($thisroombook.length > 0){
console.log($thisroombook.position().top);
console.log(parseFloat(jQuery('.room-detail-content').css('padding-top')));
jQuery('.room-detail-content').animate({scrollTop: $thisroombook.position().top + parseFloat(jQuery('.room-detail-content').css('padding-top')) + parseFloat(jQuery('#diadao-room-detail-panel').css('padding-top')) }, 400);
$thisroombook.removeClass('animated');
void $thisroombook[0].offsetWidth;
$thisroombook.addClass('animated');
}}
}
jQuery(document).on('click', '.commoncard__bookroom', (e)=> {
setTimeout(scrollToBookRoom, 500, jQuery(e.currentTarget).attr('data-roomid'));
});
jQuery(document).on('click', '.roombooking-cta a', (e)=> {
e.preventDefault();
scrollToBookRoom(jQuery(e.currentTarget).closest('.kwpb-diadao-room-detail').attr('data-roomid'));
});
jQuery('.swiper-snippet').each((e, el)=> {
if(jQuery(el).find('.swiper-slide').length <=1){
jQuery(el).addClass('noaction');
}});
const nbfaq=jQuery('.pagefaq__block').length-1;
let currentfaq=0;
let wscrolltop=jQuery(window).scrollTop();
let wheight=jQuery(window).height();
function checkcurrentfaq(){
let i=nbfaq;
wscrolltop=jQuery(window).scrollTop();
for(i=nbfaq; i>=0; i--){
currentfaq=i;
if(jQuery('.pagefaq__block').eq(i).offset().top < wscrolltop + (wheight/3)){
break;
}}
jQuery('.link-faq').removeClass('current');
jQuery('.link-faq:eq(' + currentfaq + ')').addClass('current');
const $swiperFAQmobile=jQuery('.pagefaq__stickymobile .swiper-container');
if($swiperFAQmobile.length > 0&&typeof $swiperFAQmobile[0].swiper!=='undefined'){
jQuery('.pagefaq__stickymobile .swiper-container')[0].swiper.slideTo(currentfaq);
}}
if(jQuery('.pagefaq').length > 0){
jQuery(window).on('scroll', function(){
checkcurrentfaq();
});
jQuery(window).on('resize', function(){
wheight=jQuery(window).height();
checkcurrentfaq();
});
jQuery(document).on('click', '.link-faq',(e)=> {
e.preventDefault();
let scrolltopfaq=jQuery(jQuery(e.currentTarget).attr('href')).offset().top - jQuery('#diadao-navbar').outerHeight();
if(jQuery('.pagefaq__stickymobile').length > 0) scrolltopfaq -=jQuery('.pagefaq__stickymobile').outerHeight();
jQuery('html, body').animate({
scrollTop: scrolltopfaq,
}, 400);
});
checkcurrentfaq();
}
jQuery(document).on('click', '#filmlink a, .filmlink',(e)=> {
e.preventDefault();
jQuery('body').addClass('fullmovieshown');
jQuery('#fullmovie').addClass('show');
const fullmovievideo=jQuery('#fullmovie hls-video')[0];
fullmovievideo.currentTime=0;
fullmovievideo.muted=false;
fullmovievideo.play();
if(deviceistouch){
fullmovievideo.requestFullscreen();
if(screen.orientation&&screen.orientation.lock){
screen.orientation.lock('landscape');
}}
});
jQuery('#fullmovie .btn-close').off('click');
jQuery(document).on('click', '#fullmovie .btn-close',(e)=> {
e.preventDefault();
jQuery('body').removeClass('fullmovieshown');
jQuery('#fullmovie').removeClass('show');
jQuery('#fullmovie hls-video')[0].pause();
if(screen.orientation&&screen.orientation.lock){
screen.orientation.unlock();
}});
jQuery('#fullmovie hls-video').attr('src', jQuery('#fullmovie hls-video').attr('data-src'));
}})(jQuery);