if (typeof jQuery != "undefined") {
$ = jQuery;
}
function format_time(hour, minute) {
var h = hour > 9 ? "" + hour: "0" + hour;
var m = minute > 9 ? "" + minute: "0" + minute;
return h+":"+m;
}
var bookingWidgetController = function () {
return {
config: {
language: $("html").attr("lang") ? $("html").attr("lang").replace(/[-_].*/, '') : $("html").attr("xml:lang").replace(/[-_].*/, ''),
base_url: "//kore-tulum-dot-secure-mexico2.appspot.com",
widget_url: "//kore-tulum-dot-secure-mexico2.appspot.com/korewidget/",
only_adults: "true",
local: false,
dependcencies_added: typeof(bookingWidgetController) == "undefined" ? false : bookingWidgetController.config.dependcencies_added,
datepicker_added: false,
dependencies: [
'jquery-ui',
'main_web_skeleton',
'selectric',
'jquery-i18n'
],
css_list : [
"https://cdn.paraty.es/static_files/common/plugins/dates-selector/css/datepicker_ext_inf.css?v=1.01",
"//kore-tulum-dot-secure-mexico2.appspot.com/static_1/css/kore_tulum_injection_styles/booking_widget_kore_tulum_injection_styles.css?v=1.01",
"//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css",
"https://cdn.paraty.es/static_files/common/plugins/pricescalendar/styles.css?v=1.01",
"https://cdn.paraty.es/static_files/common/css/datepicker.redmond/jquery-ui-1.8.16.custom.min.css?v=1.01"
],
/*Special configs*/
avoid_guest_autoclose_click: false
},
init: function () {
this.prepare_dependencies();
},
_getScript: function (url) {
if (this.config.local) {
url = url.replace("https://cdn.paraty.es", "http://localhost:8090");
url = url.replace("/static_files/common/", "/static_1/");
}
return $.getScript(url);
},
prepare_dependencies: function () {
var base_url = bookingWidgetController.config.base_url,
lang = bookingWidgetController.config.language;
if (!bookingWidgetController.config.dependcencies_added) {
let dependenciesToLoad = [];
for (let dependency of bookingWidgetController.config.dependencies) {
switch (dependency) {
case 'jquery-ui':
dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/lib/jquery-ui-1.10.1.custom.min.modified.js?v=1.01"));
break;
case 'main_web_skeleton':
dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/js/mainWebSkeletonAux_injection.js?v=1.01"));
break;
case 'selectric':
dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/lib/selectric/jquery.selectric.1.8.js?v=1.01"));
break;
case 'jquery-i18n':
dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/lib/jquery-i18n-1.1.1/jquery.i18n.js?v=1.01").then(function () {
return bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/i18n/messages_" + lang + ".js?v=1.01").then(function () {
$.i18n.load(messages);
});
}));
break;
default:
console.debug(`[Paraty Injection] Unknown dependency: ${dependency}`);
break;
}
}
$.when(...dependenciesToLoad).done(function () {
bookingWidgetController.get_booking_widget_html();
bookingWidgetController.config.dependcencies_added = true;
});
}
},
get_booking_widget_html: function () {
bookingWidgetController.load_css();
var language_widget = bookingWidgetController.config.language;
$("html").attr("lang", language_widget);
$.get(bookingWidgetController.config.widget_url + bookingWidgetController.config.language, function (e) {
bookingWidgetController.config.widget_html = $("
").html(e);
}).done(function () {
bookingWidgetController.add_widget_html();
bookingWidgetController.add_button_mobile_version_html();
bookingWidgetController.adding_tags_to_config();
bookingWidgetController.load_datepicker();
bookingWidgetController.open_widget();
bookingWidgetController.close_widget();
bookingWidgetController.click_listeners();
if ($("#add_analytics_campaings_tracking") && $("#add_analytics_campaings_tracking").length > 0) {
injectionCampaignsController.init()
}
});
},
load_css: function () {
var list_css = bookingWidgetController.config.css_list;
for (var i = 0; i < list_css.length; i++) {
$('head').append($('').attr('href', list_css[i]));
}
},
add_widget_html: function() {
},
add_button_mobile_version_html: function() {
let target_container = $("#widget_paraty").length ? $("#widget_paraty") : $("#widget-paraty");
target_container.append($("").html($.i18n._("reserva_ahora")));
target_container.find("#full_wrapper_booking").append($(""));
},
load_datepicker: function () {
var lang = bookingWidgetController.config.language,
base_url = bookingWidgetController.config.base_url;
// Refactor in a external function
if (!bookingWidgetController.config.datepicker_added) {
const callback = function () {
bookingWidgetController.after_load_booking_script();
bookingWidgetController.custom_functions();
bookingWidgetController.config.datepicker_added = true;
}
if (bookingWidgetController.config.dependencies.includes('jquery-ui')) {
bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/plugins/pricescalendar/calendar.plugin.js?v=1.01");
bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/js/datepicker/jquery.ui.datepicker-" + lang + ".js?v=1.01").done(function () {
bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/plugins/dates-selector/datepicker_v1.js").done(function () {
_set_datepicker_regional($);
bookingWidgetController.datepicker_configuration();
bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/scripts/booking_7.js?v=1.01").done(callback);
});
});
} else {
callback();
}
}
},
after_load_booking_script: function() {
if (bookingWidgetController.config.dependencies.includes('jquery-ui')) {
_set_datepicker_regional($);
DP_extend_info.init();
bookingWidgetController.update_date_by_timezone();
}
if (bookingWidgetController.config.dependencies.includes('selectric')) {
$(".room_selector").selectric({disableOnMobile: false});
$(".rooms_number").selectric({disableOnMobile: false});
}
bookingWidgetController.prepare_guest_selector();
bookingWidgetController.adding_room_tag_selector();
bookingWidgetController.set_occupancy_number();
},
update_date_by_timezone: function() {
if ($("#timeLimit").length>0) {
var _limit = $("#timeLimit").val();
var _now = new Date();
var _hour = format_time(_now.getHours(), _now.getMinutes());
if (_hour > _limit) {
_now.setUTCDate(_now.getUTCDate() + 1);
}
var datepicker_sd = $('.' + DP_extend_info.config.class_datepicker_sd);
datepicker_sd.datepicker('option', 'minDate', new Date(_now.getFullYear(),_now.getMonth(),_now.getDate()));
var datestart = _now.getDate()+"/"+(_now.getMonth()+1)+"/"+_now.getFullYear();
updateDates(datestart);
$("input[name='startDate']").val(datestart);
_set_start_date(datestart);
_now.setUTCDate(_now.getUTCDate() + 1);
datepicker_departure_date = $.datepicker.formatDate("dd-mm-yy", _now);
datepicker_departure_date = datepicker_departure_date.replace(new RegExp("-", "g"), '/');
$("input[name='endDate']").val(datepicker_departure_date);
_set_end_date(datepicker_departure_date);
$('.departure_datepicker').datepicker('option', 'minDate', _now);
}
},
datepicker_configuration: function() {
DP_extend_info.config.booking_version = '5';
DP_extend_info.config.hotel_path_endpoint = bookingWidgetController.config.base_url;
bookingWidgetController.separate_entry_departure_datepicker();
DP_extend_info.config.custom_format_day_month = bookingWidgetController.custom_format_date;
},
separate_entry_departure_datepicker: function() {
DP_extend_info.config.start_date_selector = ".entry_date_wrapper";
DP_extend_info.config.end_date_selector = ".departure_date_wrapper";
DP_extend_info.config.start_datepicker_span = ".entry_date_wrapper .date_day";
DP_extend_info.config.end_datepicker_span = ".departure_date_wrapper .date_day";
},
custom_format_date: function(dateComponents) {
dateComponents = dateComponents.split("/");
var month_names = $.datepicker._defaults.monthNames,
html_date = "%d
%m
%y
",
month = (parseInt(dateComponents[1]) - 1);
return html_date.replace("%d", dateComponents[0]).replace("%m", month_names[month]).replace("%y", dateComponents[2]);
},
prepare_guest_selector: function () {
$("select.room_selector").unbind("change");
$("select.room_selector, select.rooms_number").change(function () {
bookingWidgetController.set_occupancy_number();
});
},
adding_room_tag_selector: function () {
$("select.rooms_number option").each(function (index, element) {
var room_tag = parseInt($(element).val()) === 1 ? bookingWidgetController.config.room_tag : bookingWidgetController.config.rooms_tag;
$(element).text($(element).text() + " " + room_tag);
});
if (bookingWidgetController.config.dependencies.includes('selectric')) {
$("select.rooms_number").selectric("refresh");
}
},
set_occupancy_number: function () {
var number_of_rooms = $("select[name='numRooms']").val(),
adults_number = 0,
kids_number = 0,
babies_number = 0;
if (number_of_rooms) {
for (var room_loop = 1; room_loop <= number_of_rooms; room_loop++) {
var actual_select_adults = $("select[name='adultsRoom" + room_loop + "']").val(),
actual_select_kids = $("select[name='childrenRoom" + room_loop + "']").val(),
actual_select_baby = $("select[name='babiesRoom" + room_loop + "']").val();
adults_number += parseInt(actual_select_adults);
kids_number += parseInt(actual_select_kids);
babies_number += parseInt(actual_select_baby);
}
}
var target_placeholder = $(".guest_selector .placeholder_text"),
placeholder_string = bookingWidgetController.occupancy_format_html();
var room_tag = number_of_rooms === 1 ?
bookingWidgetController.config.room_tag : bookingWidgetController.config.rooms_tag;
var adult_tag = adults_number === 1 ?
bookingWidgetController.config.adult_text : bookingWidgetController.config.adults_text;
var kid_tag = kids_number === 1 ?
bookingWidgetController.config.kid_text : bookingWidgetController.config.kids_text;
var baby_tag = babies_number === 1 ?
bookingWidgetController.config.baby_text : bookingWidgetController.config.babies_text;
placeholder_string = placeholder_string.replace("@@N_R@@", number_of_rooms).replace("@@T_R@@", room_tag)
.replace("@@N_A@@", adults_number).replace("@@T_A@@", adult_tag)
.replace("@@N_C@@", kids_number).replace("@@T_C@@", kid_tag)
.replace("@@N_B@@", babies_number).replace("@@T_B@@", baby_tag);
target_placeholder.html(placeholder_string);
},
occupancy_format_html: function() {
var occupancy_string = '';
if (this.config.only_adults) {
occupancy_string = "@@N_A@@ @@T_A@@";
} else {
occupancy_string = "@@N_A@@ @@T_A@@ / @@N_C@@ @@T_C@@";
}
return occupancy_string;
},
open_widget: function () {
$("#floating_button").click(function () {
$("#full_wrapper_booking").fadeIn();
});
},
close_widget: function () {
$("i.fa-times.close_widget").click(function () {
$("#full_wrapper_booking").fadeOut();
});
},
click_listeners: function () {
if (!this.config.avoid_guest_autoclose_click) {
$("html").click(function (event) {
var event_target = $(event.target);
if (!event_target.closest(".room_list_wrapper").length && !event_target.closest(".guest_selector").length) {
$(".room_list_wrapper").slideUp();
}
});
}
},
adding_tags_to_config: function () {
bookingWidgetController.config.adults_text = $("#adults_tag").val();
bookingWidgetController.config.adult_text = $("#adult_tag").val();
bookingWidgetController.config.kids_text = $("#kids_tag").val();
bookingWidgetController.config.kid_text = $("#kid_tag").val();
bookingWidgetController.config.babies_text = $("#babies_tag").val();
bookingWidgetController.config.baby_text = $("#baby_tag").val();
bookingWidgetController.config.room_tag = $("#room_tag").val();
bookingWidgetController.config.rooms_tag = $("#rooms_tag").val();
},
force_start_date: function (forcedStartDateInput) {
function parseDate(dateString) {
const [day, month, year] = dateString.split("/").map(Number);
return new Date(year, month - 1, day);
}
function formatDate(date) {
return date.toLocaleDateString('en-GB'); // Formats as DD/MM/YYYY
}
const inputDateString = forcedStartDateInput.val();
if (!inputDateString) {
console.error("Invalid input date.");
return;
}
const startDate = parseDate(inputDateString);
if (isNaN(startDate.getTime())) {
console.error("Unable to parse the start date.");
return;
}
const endDate = new Date(startDate);
endDate.setDate(endDate.getDate() + 1);
const formattedStartDate = formatDate(startDate);
const formattedEndDate = formatDate(endDate);
const startDateInput = $("input[name='startDate']");
const endDateInput = $("input[name='endDate']");
startDateInput.val(formattedStartDate).trigger("change");
endDateInput.val(formattedEndDate).trigger("change");
window.updateDates(formattedStartDate);
const monthToSearch = startDate.getMonth();
const yearToSearch = startDate.getFullYear();
const price_calendar_v2 = $("#price_calendar_v2") && $("#price_calendar_v2").length;
if (price_calendar_v2) {
document.dispatchEvent(new CustomEvent('updateMonth.price_calendar_v2', {
detail: { month: monthToSearch, year: yearToSearch }
}));
}
},
custom_functions: function(){
}
};
}();
const injectionCampaignsController = (function () {
return {
init() {
this.processCampaignInfo();
},
getUrlParameter(sParam) {
const sPageURL = decodeURIComponent(window.location.search.substring(1));
const sURLVariables = sPageURL.split('&');
for (const sVariable of sURLVariables) {
const [key, value] = sVariable.split('=');
if (key === sParam) {
return value === undefined ? true : value;
}
}
return undefined;
},
createCookie(key, value, durationInDays = 365) {
const targetExpiryDate = new Date();
targetExpiryDate.setDate(targetExpiryDate.getDate() + durationInDays);
document.cookie = `${key}=${value};path=/;expires=${targetExpiryDate.toUTCString()};`;
},
searchCookie(key) {
const cookies = document.cookie.split(';');
for (const cookie of cookies) {
const [cookieKey, cookieValue] = cookie.trim().split('=');
if (cookieKey === key) {
return cookieValue;
}
}
return undefined;
},
saveCampaignInfo() {
const availableCampaignParams = [
'utm_source', 'utm_medium', 'utm_campaign', 'utm_term',
'utm_content', 'utm_id', 'partner'
];
const cookieToSet = {};
availableCampaignParams.forEach(param => {
const retrievedParam = this.getUrlParameter(param);
if (retrievedParam) {
cookieToSet[param] = retrievedParam;
}
});
if (!$.isEmptyObject(cookieToSet)) {
const cookieToSetJson = JSON.stringify(cookieToSet);
this.createCookie("analytics_campaign", cookieToSetJson);
}
},
addCampaignToWidget() {
const retrievedCookie = this.searchCookie('analytics_campaign');
if (!retrievedCookie) return;
const loadedCookie = JSON.parse(retrievedCookie);
$(".paraty-booking-form").each(function () {
for (const [keyCampaign, value] of Object.entries(loadedCookie)) {
const inputToAppend = $("").attr({
name: keyCampaign,
value: value
});
$(this).append(inputToAppend);
}
});
},
processCampaignInfo() {
this.saveCampaignInfo();
this.addCampaignToWidget();
}
};
})();
bookingWidgetController.config.avoid_guest_autoclose_click = true;
bookingWidgetController.add_widget_html = function () {
var paraty_widget = bookingWidgetController.config.widget_html;
if (!$("#widget_paraty").length) {
$("body").append($(""));
$("#widget_paraty").addClass('auto-position');
}
$("#widget_paraty").html(paraty_widget);
if ($("#widget_paraty input#extra_widget_class").length)
$("body").addClass($("#widget_paraty input#extra_widget_class").val());
$("#widget_paraty #full_wrapper_booking .booking_form_title").append($(".cancel_booking_link"));
if ($("#widget_paraty .destination_wrapper").length) {
$("#widget_paraty").addClass('has-hotel-selector');
}
$("#widget_paraty .booking_steps").detach().appendTo($('body'));
};
bookingWidgetController.add_button_mobile_version_html = function () {
if (!$("#floating_button_paraty").length) {
$("body").append($("").html($.i18n._("reserva_ahora")));
$("#floating_button_paraty").addClass('auto-position');
}
$("#widget_paraty #full_wrapper_booking").append($(""));
}
bookingWidgetController.custom_format_date = function (dateComponents) {
dateComponents = dateComponents.split("/");
var html_date = "%d %m";
let date = new Date();
date.setMonth(dateComponents[1] - 1);
let month = date.toLocaleString([], {
month: 'short',
});
month = month.charAt(0).toUpperCase() + month.slice(1);
return html_date.replace("%d", dateComponents[0]).replace("%m", month);
};
bookingWidgetController.occupancy_format_html = function () {
return "@@N_A@@/@@N_C@@/@@N_B@@";
};
bookingWidgetController.adding_room_tag_selector = function () {
$("select.rooms_number option").each(function (index, element) {
$(element).text($(element).text());
});
$("select.rooms_number").selectric("refresh");
};
bookingWidgetController.open_widget = function () {
$("#floating_button_paraty").click(function (e) {
e.preventDefault();
$("#widget_paraty").fadeToggle();
});
};
bookingWidgetController.close_widget = function () {
$("i.fa-times.close_widget").click(function () {
$("#widget_paraty").fadeOut();
});
};
bookingWidgetController.custom_functions = function () {
bookingWidgetController.config.languages = {
"es": "SPANISH",
"en": "ENGLISH"
};
//Get fontawesome 6
var script_fa_tag = document.createElement('script');
script_fa_tag.src = 'https://kit.fontawesome.com/d8b9925505.js';
script_fa_tag.setAttribute("defer", "");
document.head.appendChild(script_fa_tag);
booking_engine_controller();
prepare_guests_selector();
set_occupancy_number();
room_selector_dates();
init_calendar();
scroll_body_class();
$("#full_wrapper_booking .children_selector select.room_selector").change(function () {
check_kids_ages($(this));
});
if ($("#booking").length) {
$("#full_wrapper_booking .kidAgesSelect").selectric();
}
let hotel_preselection = $("#widget_paraty").attr('data-hotel-preselection');
if (hotel_preselection) {
$("#widget_paraty .hotel_selector_option#" + hotel_preselection).click();
}
//individual_hotel_personalization();
};
function init_calendar() {
window.calendar_data.change_date_callback = function (date, isStartDateSelection) {
function format(inputDate) {
let date, month, year;
date = inputDate.getDate();
month = inputDate.getMonth() + 1;
year = inputDate.getFullYear();
date = date.toString().padStart(2, '0');
month = month.toString().padStart(2, '0');
return `${date}/${month}/${year}`;
}
let widget_form_wrapper = $('#full_wrapper_booking .paraty-booking-form');
let date_formated = format(date);
let day_month_format = $.datepicker.formatDate('dd M', date);
let year_format = $.datepicker.formatDate('yy', date);
if (isStartDateSelection) {
widget_form_wrapper.find('input[name=startDate]').val(date_formated);
widget_form_wrapper.find('.entry_date .date_day').html(day_month_format);
widget_form_wrapper.find('.entry_date .date_year').html(year_format);
} else {
widget_form_wrapper.find('input[name=endDate]').val(date_formated);
widget_form_wrapper.find('.departure_date .date_day').html(day_month_format);
widget_form_wrapper.find('.departure_date .date_year').html(year_format);
$(".booking_steps .step_3").trigger('click');
$('.booking_steps .step_2').addClass('done');
}
load_new_room_dates();
};
}
function prepare_guests_selector() {
$("select.room_selector").unbind("change");
$(".room_selector").selectric('destroy');
$(".room_selector").selectric({disableOnMobile: false});
$("select.room_selector, select.rooms_number").change(function () {
set_occupancy_number();
});
$(".remove_room_element").click(function () {
var actual_room_numbers = $("select.rooms_number").val();
if (actual_room_numbers > 1) {
var target_room_number = parseInt(actual_room_numbers) - 1;
$("select.rooms_number option").removeAttr('selected');
$("select.rooms_number option[value='" + target_room_number + "']").attr('selected', 'selected');
$(".room" + actual_room_numbers).hide();
$("select.rooms_number").val(target_room_number);
$("select.rooms_number").selectric("refresh");
}
set_occupancy_number()
});
var add_room_html = "" + $.i18n._('T_add_new_room') + "
",
remove_room_html = "" + $.i18n._('T_remove_room') + "
",
close_btn = "",
close_calendar_btn = "",
booking_btn = "";
$(".room_list_wrapper").append(close_btn);
$(".calendar_root_wrapper").append(close_calendar_btn);
$(".room_list_wrapper .room_list .room").each(function () {
$(this).append(add_room_html);
});
$(".room_list_wrapper .room_list .room2").append(remove_room_html);
$(".room_list_wrapper .room_list .room3").append(remove_room_html);
$(".add_room").click(add_room);
$(".remove_room").click(remove_room);
$(".room_list_wrapper .room_list").append(booking_btn);
$(".wrapper_booking_button_guest .submit_button").click(function () {
var promocode_val = $(".wrapper_booking_button_guest .promocode_input").val(),
promocode_original = $(".wrapper_booking_button .promocode_input").val();
if (promocode_val != '' && promocode_val != promocode_original) {
$(".wrapper_booking_button .promocode_input").val(promocode_val)
}
$(".wrapper_booking_button .submit_button").click();
});
$(document).on("click", ".close_guest_selector, .close_calendar_app", function () {
$(".booking_steps .step_1, .booking_steps .step_2, .booking_steps .step_3").removeClass("current_step");
$(".hotel_selector").slideUp();
$(".calendar_root_wrapper").slideUp();
$(".room_list_wrapper").slideUp();
$("#full_wrapper_booking").removeClass("fixed");
$("#widget_paraty").removeClass("open");
$('.booking_steps').hide();
$("body").removeClass("widget_paraty_open");
});
$(".adults_selector .selectric-room_selector .label").click(function () {
change_selectric_rooms($(this), ".selectric-room_selector", "select.room_selector", 8, 0, 1);
});
$(".adults_selector .selectric-room_selector .button").click(function () {
change_selectric_rooms($(this), ".selectric-room_selector", "select.room_selector", 9, 1, -1);
});
$(".children_selector .selectric-room_selector .label").click(function () {
change_selectric_rooms($(this), ".selectric-room_selector", "select.room_selector", 4, -1, 1);
});
$(".children_selector .selectric-room_selector .button").click(function () {
change_selectric_rooms($(this), ".selectric-room_selector", "select.room_selector", 5, 0, -1);
});
$(".babies_selector .selectric-room_selector .label").click(function () {
change_selectric_rooms($(this), ".selectric-room_selector", "select.room_selector", 4, -1, 1);
});
$(".babies_selector .selectric-room_selector .button").click(function () {
change_selectric_rooms($(this), ".selectric-room_selector", "select.room_selector", 5, 0, -1);
});
}
function change_selectric_rooms(element, parent_class, select, max, min, operator) {
var selectric_element = element.closest(parent_class).find(select),
label_for = element.closest(".range_label_enabled");
if (parseInt(selectric_element.val()) > min &&
parseInt(selectric_element.val()) < max) {
var new_select_val = parseInt(selectric_element.val()) + operator;
selectric_element.val(new_select_val);
selectric_element.selectric('refresh');
set_occupancy_number();
}
}
function add_room() {
var number_rooms = parseInt($("select.rooms_number").val());
if (number_rooms < 3) {
$($(".selectric-rooms_number .selectricItems li").get(number_rooms)).trigger("click");
set_occupancy_number();
}
if (number_rooms == 1) {
$(".room1 .add_room").hide();
}
if (number_rooms == 2) {
$(".add_room").hide();
$(".room2 .remove_room").hide();
}
}
function remove_room() {
var number_rooms = parseInt($("select.rooms_number").val());
if (number_rooms > 1) {
$($(".selectric-rooms_number .selectricItems li").get(number_rooms - 2)).trigger("click");
set_occupancy_number();
}
if (number_rooms == 2) {
$(".room1 .remove_room").show();
$(".room1 .add_room").show();
}
if (number_rooms == 3) {
$(".room2 .remove_room").show();
$(".room2 .add_room").show();
}
$("select.rooms_number").change(function (event) {
var number = $(this).val(),
_room1 = $(".room1"),
_room2 = $(".room2"),
_room3 = $(".room3"),
_room_age1 = $(".room_ages_1"),
_room_age2 = $(".room_ages_2"),
_room_age3 = $(".room_ages_3");
if (number == 1) {
_room2.hide().promise().done(function () {
_room2.css("overflow", "initial");
});
_room_age2.removeClass("show")
_room_age3.removeClass("show")
_room3.hide().promise().done(function () {
_room3.css("overflow", "initial");
});
$(".horizontal_engine").css("height", "379px");
} else if (number == 2) {
_room2.show("fast").promise().done(function () {
_room2.css("overflow", "initial");
});
_room_age3.removeClass("show")
_room3.hide().promise().done(function () {
_room3.css("overflow", "initial");
});
$(".horizontal_engine").css("height", "449px");
} else {
_room2.show("fast").promise().done(function () {
_room2.css("overflow", "initial");
});
_room3.show().promise().done(function () {
_room3.css("overflow", "initial");
});
$(".horizontal_engine").css("height", "518px");
}
});
}
function toggle_guest_selector() {
var target_room_wrapper = $(".room_list_wrapper");
if (!target_room_wrapper.hasClass('active')) {
target_room_wrapper.addClass('active');
target_room_wrapper.show();
console.log("showing");
} else {
target_room_wrapper.removeClass('active');
target_room_wrapper.hide();
}
set_occupancy_number();
}
function set_occupancy_number() {
var number_of_rooms = $("select[name='numRooms']").val(),
adults_number = 0,
kids_number = 0,
babies_number = 0;
if (number_of_rooms) {
for (var room_loop = 1; room_loop <= number_of_rooms; room_loop++) {
var actual_select_adults = $("select[name='adultsRoom" + room_loop + "']").val(),
actual_select_kids = $("select[name='childrenRoom" + room_loop + "']").val(),
actual_select_baby = $("select[name='babiesRoom" + room_loop + "']").val();
if (actual_select_adults || actual_select_kids) {
adults_number += parseInt(actual_select_adults);
kids_number += parseInt(actual_select_kids);
babies_number += parseInt(actual_select_baby);
}
}
}
var target_placeholder = $(".guest_selector .placeholder_text"),
placeholder_string = "";
adults_number = parseInt(adults_number);
kids_number = parseInt(kids_number);
babies_number = parseInt(babies_number);
placeholder_string += "" + adults_number + " / " + kids_number + "";
if (target_placeholder.hasClass("adults_only")) {
placeholder_string = "" + adults_number + " " + $.i18n._("T_adultos") + "";
}
target_placeholder.html(placeholder_string);
}
bookingWidgetController.after_load_booking_script = function() {
_set_datepicker_regional($);
$(".room_selector").selectric({disableOnMobile: false});
$(".rooms_number").selectric({disableOnMobile: false});
bookingWidgetController.prepare_guest_selector();
bookingWidgetController.adding_room_tag_selector();
bookingWidgetController.set_occupancy_number();
bookingWidgetController.update_date_by_timezone();
};
bookingWidgetController.datepicker_configuration = function () {
let is_mobile = ($(window).width() <= 1140);
DP_extend_info.config.booking_version = '5';
DP_extend_info.config.hotel_path_endpoint = bookingWidgetController.config.base_url;
DP_extend_info.config.months_show = (is_mobile) ? 1 : 2;
DP_extend_info.config.months_show_highlight = true;
DP_extend_info.config.force_hightlight = true;
DP_extend_info.config.custom_format_day_month = function (dateComponents) {
dateComponents = dateComponents.split("/");
var month_short = $.datepicker._defaults['monthNamesShort'][parseInt(dateComponents[1], 10) - 1];
return "" + dateComponents[0] + "" + month_short + "";
};
DP_extend_info.init();
};
function room_selector_dates() {
var room_list_wrapper = $('.room_list_wrapper .room_list'),
dates_wrapper = $('');
if (room_list_wrapper.length) {
room_list_wrapper.prepend(dates_wrapper);
}
$('.dates_wrapper, .stay_selection').on('click', function () {
$(".booking_steps .step_2").trigger('click');
});
}
function check_kids_ages(select_element) {
var parent_list = select_element.closest("li"),
selected_value = select_element.val(),
target_age_selector = parent_list.next(".full_ages_wrapper"),
childs_elements = target_age_selector.find(".kid_age_element_wrapper"),
target_childs_elements = childs_elements.slice(0, parseInt(selected_value));
if (parseInt(selected_value)) {
childs_elements.css('display', 'none');
target_childs_elements.css('display', 'block');
target_age_selector.slideDown(function () {
$(this).css("overflow", "inherit");
});
} else {
childs_elements.css('display', 'none');
target_age_selector.slideUp(function () {
$(this).css("overflow", "inherit");
});
}
}
function load_new_room_dates() {
if ($('.dates_wrapper').length) {
var start_date = $.datepicker.parseDate("dd/mm/yy", $("input[name=startDate]").val()),
start_date_format = $.datepicker.formatDate("dd MM", start_date),
end_date = $.datepicker.parseDate("dd/mm/yy", $("input[name=endDate]").val()),
end_date_format = $.datepicker.formatDate("dd MM", end_date),
hotel_name = $('.destination_wrapper .destination').val();
$(".room_info_wrapper .dates_wrapper").html(start_date_format + ' - ' + end_date_format);
if (hotel_name) {
$(".room_info_wrapper .hotel_name_rooms").html(hotel_name).addClass('with_name');
}
}
}
function booking_engine_controller() {
let widget = $("#widget_paraty"),
booking_form = widget.find('.booking_form'),
hotel_preselection = widget.attr('data-hotel-namespace'); // TODO
$(".destination_wrapper").click(function () {
$(".booking_steps .step_1, .booking_steps .step_2, .booking_steps .step_3").removeClass("current_step");
$(".close_button_datepicker").click();
$(".close_room_selector").click();
$(".hotel_selector").slideDown();
$(".booking_steps .step_1").addClass("current_step");
$("#widget_paraty").addClass("open");
$('.booking_steps').show();
$("body").addClass("widget_paraty_open");
$("#full_wrapper_booking").addClass("fixed");
load_new_room_dates();
if ($("#filter_selector").length) {
_filter_selector($(this));
}
});
widget.find(".hotel_selector_option").click(function () {
widget.find(".hotel_selector").hide("fast");
widget.find(".hotel_selector_option").removeClass("selected");
$(this).addClass("selected");
if ($(this).data("only-adults") === true) {
widget.find(".children_selector").hide("fast");
widget.find(".adults_selector").addClass("adults_only");
widget.find(".guest_selector .placeholder_text").addClass("adults_only");
set_occupancy_number()
} else {
widget.find(".children_selector").show("fast");
widget.find(".adults_selector").removeClass("adults_only");
widget.find(".guest_selector .placeholder_text").removeClass("adults_only");
set_occupancy_number()
}
let new_placeholder_html = $(this).find(".title_selector").html().replace("
", " ").replace("&", "&").replace(/<.*?>/g, ""),
id_hotel_4_url = $(this).attr("id"),
new_namespace = widget.find("#namespace_" + id_hotel_4_url).val(),
url_booking = widget.find("#url_booking_" + id_hotel_4_url).val(),
hotel_value = url_booking.indexOf('http') > -1 ? url_booking : "https://" + id_hotel_4_url + url_booking;
//Change calendar namespace
window.calendar_data.update_namespace_calendar(new_namespace);
$('.price_calendar_wrapper .toggle_chart').css('opacity', '1').css('pointer-events', 'auto');
//change the value
widget.find(".destination").val(new_placeholder_html);
booking_form.attr("action", hotel_value).find("#namespace").val(new_namespace);
});
$(document).on("click", ".booking_steps .step_1", function () {
$(".booking_steps .step_2, .booking_steps .step_3").removeClass("current_step");
$(".close_button_datepicker").click();
$(".close_room_selector").click();
$(".close_calendar_app").click();
$(".hotel_selector").slideDown();
$(".booking_steps .step_1").addClass("current_step");
$("#widget_paraty").addClass("open");
$('.booking_steps').show();
$("body").addClass("widget_paraty_open");
$("#full_wrapper_booking").addClass("fixed");
load_new_room_dates();
});
$(document).on("click", ".booking_steps .step_2:not(.current_step)", function () {
$(".booking_steps .step_1, .booking_steps .step_3").removeClass("current_step");
$(".hotel_selector .close").click();
$(".close_room_selector").click();
$(".calendar_root_wrapper").slideDown();
$(".booking_steps .step_2").addClass("current_step");
$("#widget_paraty").addClass("open");
$('.booking_steps').show();
$("body").addClass("widget_paraty_open");
$("#full_wrapper_booking").addClass("fixed");
load_new_room_dates();
});
$(document).on("click", ".booking_steps .step_3:not(.current_step)", function () {
$(".guest_selector").click();
load_new_room_dates();
});
$(".guest_selector").click(function () {
$(".booking_steps .step_1, .booking_steps .step_2, .booking_steps .step_3").removeClass("current_step");
$(".hotel_selector").slideUp();
$(".calendar_root_wrapper").slideUp();
$(".room_list_wrapper").slideDown();
$(".booking_steps .step_3").addClass("current_step");
$("#widget_paraty").addClass("open");
$('.booking_steps').show();
$("body").addClass("widget_paraty_open");
$("#full_wrapper_booking").addClass("fixed");
load_new_room_dates();
});
$(".hotel_selector_inner li").click(function (e) {
$(".booking_steps .step_1").removeClass("current_step");
$('.booking_steps .step_1').addClass('done');
if (!$("#widget_paraty").hasClass("dates_selected")) {
$("#widget_paraty").addClass("open");
$('.booking_steps').show();
$("body").addClass("widget_paraty_open");
$(".booking_steps .step_2").addClass("current_step");
$(".calendar_root_wrapper").slideDown();
load_new_room_dates();
} else {
if ($("#full_wrapper_booking").hasClass("fixed")) {
$(".hotel_selector").hide();
$(".booking_steps .step_2").removeClass("current_step");
$("body").addClass("widget_paraty_open");
if (!$('.calendar_app').is(':visible')){
$("#widget_paraty").addClass("open");
$('.booking_steps').show();
$("body").addClass("widget_paraty_open");
$(".booking_steps .step_3").addClass("current_step");
$(".room_list_wrapper").slideDown();
load_new_room_dates();
}
}
}
});
$(".hotel_selector .booking_0_hotel_selection").click(function () {
$(".hotel_selector").slideUp();
$(".booking_steps .step_1").removeClass("current_step");
$('.booking_steps .step_1').addClass('done');
$("#widget_paraty").addClass("open");
$('.booking_steps').show();
$("body").addClass("widget_paraty_open");
$(".booking_steps .step_2").addClass("current_step");
$(".calendar_root_wrapper").slideDown();
window.calendar_data.update_namespace_calendar("");
$('.price_calendar_wrapper .toggle_chart').css('opacity', '0.6').css('pointer-events', 'none');
let new_placeholder_html = $(this).find('.title_booking0').html().trim();
widget.find(".destination").val(new_placeholder_html);
});
$(".close_button_datepicker").unbind("click");
$(".close_button_datepicker").click(function () {
$("#widget_paraty").removeClass("open");
$('.booking_steps').hide();
$("body").removeClass("widget_paraty_open");
$("#full_wrapper_booking").removeClass("fixed");
$(".booking_steps .step_2").removeClass("current_step");
});
$(".hotel_selector .close").click(function (e) {
e.preventDefault();
$(this).toggleClass("active");
$(".hotel_selector").slideUp();
$("booking_steps .step_1").removeClass("current_step");
$("#widget_paraty").removeClass("open");
$('.booking_steps').hide();
$("body").removeClass("widget_paraty_open");
$("#full_wrapper_booking").removeClass("fixed");
});
$(".wrapper_booking_button .submit_button").click(function () {
if ($(".destination_fieldo input[name=destination]").val() !== "") {
$(".booking_steps .step_1, .booking_steps .step_2, .booking_steps .step_3").removeClass("current_step");
$(".close_button_datepicker").click();
$(".close_room_selector").click();
} else {
$(".booking_steps .step_1").click();
}
});
}
function scroll_body_class() {
$(window).scroll(function () {
if ($(this).scrollTop() > 775) {
$('#widget_paraty').addClass('fixed');
} else {
$('#widget_paraty').removeClass('fixed');
}
});
}
bookingWidgetController.init();