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: "//casualhoteles.com", widget_url: "//casualhoteles.com/casualloyaltywidget/", only_adults: "", 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.02", "//casualhoteles.com/static_1/css/casual_loyalty/booking_widget_casual_loyalty.css?v=1.02", "//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.02", "https://cdn.paraty.es/static_files/common/css/datepicker.redmond/jquery-ui-1.8.16.custom.min.css?v=1.02" ], /*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.02")); break; case 'main_web_skeleton': dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/js/mainWebSkeletonAux_injection.js?v=1.02")); break; case 'selectric': dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/lib/selectric/jquery.selectric.1.8.js?v=1.02")); 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.02").then(function () { return bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/i18n/messages_" + lang + ".js?v=1.02").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.02"); bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/js/datepicker/jquery.ui.datepicker-" + lang + ".js?v=1.02").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.02").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']"); const previosStartDate = parseDate(startDateInput.val()); const previousCalelendarMonth = previosStartDate.getMonth(); const previousCalelendarYear = previosStartDate.getFullYear(); 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; const calendarChange = previousCalelendarMonth !== monthToSearch || previousCalelendarYear !== yearToSearch; if (price_calendar_v2 && calendarChange) { 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', 'dsclid', 'fbclid', 'gclid']; const cookieToSet = {}; availableCampaignParams.forEach(param => { const retrievedParam = this.getUrlParameter(param); if (retrievedParam) { cookieToSet[param] = retrievedParam; } }); if (!$.isEmptyObject(cookieToSet)) { cookieToSet['campaign_timestamp'] = this.getCampaignTimestamp(); const cookieToSetJson = JSON.stringify(cookieToSet); this.createCookie("analytics_campaign", cookieToSetJson); } }, getCampaignTimestamp() { const date = new Date(); const timezoneOffset = -date.getTimezoneOffset() / 60; return date.toISOString().replace('T', ' ').slice(0, -1) + ` (${timezoneOffset >= 0 ? `GMT+${timezoneOffset}` : `GMT${timezoneOffset}`})`; }, 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.language = getAbbreviatedLanguage('SPANISH'); bookingWidgetController.add_widget_html = function () { const widget_html = bookingWidgetController.config.widget_html; if (!$("#widget_paraty").length) { $("body").append($("
")); } const widget_paraty = $("#widget_paraty"); widget_paraty.html(widget_html); if (widget_paraty.find(".destination_wrapper").length) { widget_paraty.addClass('has-hotel-selector'); } if($(".motor-container").length) { $(".motor-container").html(widget_paraty).addClass("paraty_widget_container"); } }; bookingWidgetController.custom_format_date = function (dateComponents) { if (dateComponents) { dateComponents = dateComponents.split("/"); const month_short = $.datepicker._defaults['monthNamesShort'][parseInt(dateComponents[1], 10) - 1]; return "" + dateComponents[0] + "" + month_short + " " + dateComponents[2] + ""; } }; bookingWidgetController.set_occupancy_number = function () { var number_of_rooms = $("select[name='numRooms']").val(), adults_number = 0, kids_number = 0, babies_number = 0, pets_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(), actual_select_pets = $("select[name='petsRoom" + 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); pets_number += parseInt(actual_select_pets); } } } var target_placeholder = $(".guest_selector .placeholder_text"), adult_tag = adults_number === 1 ? bookingWidgetController.config.adult_text : bookingWidgetController.config.adults_text, placeholder_string = "" + adults_number + " " + adult_tag; adults_number = parseInt(adults_number); kids_number = parseInt(kids_number); babies_number = parseInt(babies_number); pets_number = parseInt(pets_number); if (!$(".adults_only_selector").length) { if (kids_number) { placeholder_string = "" + adults_number + "/" + kids_number + " "; } if (babies_number) { placeholder_string += "/" + babies_number + ""; } if (pets_number) { placeholder_string += "/" + pets_number + ""; } } target_placeholder.each(function () { $(this).html(placeholder_string); }); }; bookingWidgetController.load_datepicker = function () { var lang = bookingWidgetController.config.language, base_url = bookingWidgetController.config.base_url; $.getScript(base_url + "/static_1/plugins/pricescalendar/calendar.plugin.js"); $.getScript(base_url + "/static_1/js/datepicker/jquery.ui.datepicker-" + lang + ".js").done(function () { $.getScript(base_url + "/static_1/plugins/dates-selector/datepicker_v1.js").done(function () { _set_datepicker_regional($); $.when( $.getScript(base_url + "/static_1/scripts/booking_7.js") ).then(function () { bookingWidgetController.datepicker_configuration(); bookingWidgetController.after_load_booking_script(); bookingWidgetController.custom_functions(); }); }); }); }; bookingWidgetController.datepicker_configuration = datepickerConfigs; bookingWidgetController.adding_room_tag_selector = function () { $("select.rooms_number option").each(function (index, element) { $(element).text($(element).text()); }); $("select.rooms_number").selectric("refresh"); }; bookingWidgetController.floating_widget = function(){ var actual_position = $(window).scrollTop(), widget = $("#widget_paraty"), header_height = $(".col").length ? $(".col").first().outerHeight() : 100, widget_position = header_height - (widget.outerHeight() - 60); if (actual_position >= widget_position && !widget.hasClass("floating_widget")) { widget.addClass("floating_widget"); } else if (actual_position < widget_position && widget.hasClass("floating_widget")) { widget.removeClass("floating_widget"); } }; bookingWidgetController.close_widget = function () { $(document).ready(function () { $(".close_widget").click(function () { $("#full_wrapper_booking").fadeOut(); }); }) }; bookingWidgetController.toggle_destinies = function () { const destinies = $(".hotel_selector .destiny"); destinies.each(function () { const btn = $(this).find("h3"); const actual_destiny = $(this); btn.click(function () { actual_destiny.toggleClass("active") }); }); }; bookingWidgetController.getUrlParameter = function (sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; bookingWidgetController.getUrlPromocode = function () { const paraty_promocode = bookingWidgetController.getUrlParameter("paraty_promocode"); if (paraty_promocode) { $("#widget_paraty #full-booking-engine-html-7 .promocode_input").val(paraty_promocode); } }; bookingWidgetController.custom_functions = function () { setWidgetData('', '', ''); addCustomParams(); bindHotelSelectorEvents(); updateRoomsCapacity(); bindOccupancyEvents(); const closeWidget = $(""); $("i.close_widget, svg.close_widget").detach().promise().done(function () { closeWidget.appendTo("#full_wrapper_booking"); closeWidget.on('click', function () { $("#widget_paraty.widget_popup").removeClass("active"); $("body").removeClass("widget_opened"); }); }); const button = $("#full-booking-engine-html-7 .submit_button"); $(button).click(function () { const targetDestination = $(".paraty-booking-form").find(".destination").val(); if (!targetDestination) { setTimeout(function(){ $(".paraty-booking-form").find(".submit_button").removeAttr('disabled'); }, 500); return false; } checkUserLogged(); button.html(''); }); $(document).ready(function () { bookingWidgetController.floating_widget(); bookingWidgetController.getUrlPromocode(); }); $(window).scroll(bookingWidgetController.floating_widget); const is_mobile = window.innerWidth < 776; //Number retreived from responsive styles if (is_mobile) { $(".guest_selector").click(function(){ setTimeout(function(){ if($(".room_list_wrapper").is('visible')) { return; } $("#full_wrapper_booking").animate({ scrollTop: 200 }); }, 500) }) } }; bookingWidgetController.init(); // Functions // General function getAbbreviatedLanguage(language) { if (language.length === 2) return language; return 'es'; } function addAttributesToElement(value, attributes, element) { if (value) { value = value.replace("
", " ") .replace("&", "&") .replace(/<.*?>/g, "") .replace(/(\r\n|\n|\r)/gm, "") .trim(); element.attr(attributes.reduce((mappedAttributes, attr) => (mappedAttributes[attr] = value, mappedAttributes), {})); } } function setWidgetData(action, namespace, applicationIds) { const bookingWidgets = $(".booking_form, #calendar_booking_form, #searchForm"); $.each(bookingWidgets, function () { $(this).attr("action", action); $(this).find("#namespace").val(namespace); $(this).find("#applicationIds").val(applicationIds); }); } function trimNamespace(namespace) { if (namespace[namespace.length - 1] == ';'){ return namespace.slice(0, -1); } return namespace; } function addCustomParams() { const form = $("#widget_paraty").find("form"); form.append(""); checkUserLogged(form); } function getCookie (key) { const cookie = document.cookie.match(new RegExp(`(^| )${key}=([^;]+)`)); if (cookie) return cookie[2]; } function checkUserLogged(form = $("#widget_paraty").find("form")) { const userSession = getCookie('loged_user'); if (!userSession) return; form.append(``); } // Hotel Selector function bindHotelSelectorEvents() { bindSelectDestiny(); bindSelectHotel(); $(".destination_field, .close_hotel_selector, .hotel_selector_option").click(function () { if ($("#full_wrapper_booking").hasClass("hotel_selector_opened")) { $("#full_wrapper_booking").removeClass("hotel_selector_opened"); } else { $("#full_wrapper_booking").addClass("hotel_selector_opened"); } }); $(".close_hotel_selector").click(function () { $(".hotel_selector").slideUp("slow"); }); } function bindSelectHotel() { $(".hotel_selector_option").click(function() { const id_hotel_4_url = $(this).attr("id"); const new_namespace = $("#namespace_" + id_hotel_4_url).val(); const url_booking = $("#url_booking_" + id_hotel_4_url).val(); const hotel_value = url_booking.indexOf('http') > -1 ? url_booking : "https://" + id_hotel_4_url + url_booking; $(".hotel_selector").hide("fast"); $(".hotel_selector_option").removeClass("selected"); $(this).addClass("selected"); addAttributesToElement($(this).find(".title_selector").html(), ["placeholder", "value"], $(".destination")); setWidgetData(hotel_value, new_namespace, ''); if ($("#kids_range_age_" + id_hotel_4_url)) { const new_range_kids_age = $("#kids_range_age_" + id_hotel_4_url).val(); const list_range = new_range_kids_age ? new_range_kids_age.split(':') : []; if (list_range.length == 2) { let new_options = ""; for (i = parseInt(list_range[0]); i <= parseInt(list_range[1]); i++) { new_options += ""; } $('.kidAgesSelect').find('option').remove().end().append(new_options).val(list_range[1]); } } }); } function bindSelectDestiny() { $(".destiny_element .destiny[data-namespace]").click(function() { $(".hotel_selector").hide("fast"); $(".hotel_selector_option").removeClass("selected"); $(this).addClass("selected"); addAttributesToElement($(this).html(), ["placeholder", "value"], $(".destination")); const url = $(this).siblings('.hotels_list').find('[id^="url_"]').val() || ""; const hotelNamespace = trimNamespace($(this).data("namespace")); const hotelUrlBooking = $(this).data("url_booking"); const hotelUrlBookingFormatted = hotelUrlBooking.includes('/') ? hotelUrlBooking : `/${hotelUrlBooking}`; const isBooking0 = hotelUrlBookingFormatted.indexOf('booking0') > -1; const booking0Url = url ? url.replace('/booking1', hotelUrlBookingFormatted) : hotelUrlBookingFormatted; const completeBookingUrl = (hotelUrlBookingFormatted.indexOf('http') > -1 || isBooking0) ? booking0Url : "https://" + hotelNamespace + hotelUrlBookingFormatted; setWidgetData(completeBookingUrl, isBooking0 ? '' : hotelNamespace, hotelNamespace); }); } // Occupancy function bindOccupancyEvents() { const occupancyWrapper = $("#occupancy_wrapper"); occupancyWrapper.find(".plus").click(function () { increaseOccupancyElement($(this)); }); occupancyWrapper.find(".minus").click(function () { decreaseOccupancyElement($(this)); }); occupancyWrapper.find(".input_simulator").change(function () { agesChecker($(this)); }); occupancyWrapper.find(".title_wrapper").click(function () { occupancyWrapper.addClass("hide"); $("body").removeClass('occupancy_selection'); }); $(".age_option").click(function () { const agesWrapper = $(this).closest('.block_age_selection'); agesWrapper.find(".age_option").removeClass('active'); $(this).addClass('active'); }); const widget = $("#widget_paraty"); const realNumRoomsInput = widget.find(".selectricWrapper.rooms_number select[name='numRooms']"); $(document).on('change', realNumRoomsInput, function () { const numRooms = widget.find("#occupancy_wrapper .rooms_amount input").val(); const roomsOptions = widget.find('.occupancy_options .room_element_options'); roomsOptions.each(function (index) { $(this).toggleClass('hide', index >= numRooms); }); }); const occupancyOverlay = $("
"); $(".rooms_number_wrapper").append(occupancyOverlay.clone()); $(".guest_selector").append(occupancyOverlay.clone()); $(".occupancy_overlay").click(function () { const currentPosition = $(window).scrollTop(); const bookingTop = $("#full_wrapper_booking").offset().top - 200; if (currentPosition > bookingTop) { occupancyWrapper.addClass("occupancy_down"); } else { occupancyWrapper.removeClass("occupancy_down"); } occupancyWrapper.toggleClass("hide"); $("body").toggleClass('occupancy_selection'); }); $("body > .black_overlay").click(function () { $("body").removeClass('occupancy_selection'); }); } function updateRoomsCapacity() { $(".paraty-booking-form").each(function () { const $form = $(this); const roomsNumber = parseInt($form.find("select.rooms_number").val()); const roomString = roomsNumber + " " + $.i18n._(roomsNumber < 2 ? "T_habitacion" : "T_habitaciones") + ", "; const hasBabies = $form.find('select.babies_room_1').length; const hasPets = $form.hasClass('has_pets_select'); const totalOccupancy = { adults: 0, children: 0, babies: hasBabies ? 0 : -1, pets: hasPets ? 0 : -1 }; for (let roomIndex = 1; roomIndex <= roomsNumber; roomIndex++) { totalOccupancy.adults += parseInt($form.find(`select.adults_room_${roomIndex}`).val()) || 0; totalOccupancy.children += parseInt($form.find(`select.children_room_${roomIndex}`).val()) || 0; if (hasBabies) { totalOccupancy.babies += parseInt($form.find(`select.babies_room_${roomIndex}`).val()) || 0; } if (hasPets) { totalOccupancy.pets += parseInt($form.find(`select.pets_room_${roomIndex}`).val()) || 0; } } const capacityPlaceholder = roomString + [totalOccupancy.adults, totalOccupancy.children].join("/") + (totalOccupancy.babies >= 0 ? '/' + totalOccupancy.babies : '') + (totalOccupancy.pets >= 0 ? '/' + totalOccupancy.pets : ''); $form.find(".guest_selector .placeholder_text").html(capacityPlaceholder); }); } function increaseOccupancyElement(element) { if (element.hasClass('disabled')) return; const wrapper = element.closest(".modification_buttons"); const targetInput = wrapper.find("input"); const targetModification = targetInput.attr('target'); const maxValue = parseInt(targetInput.attr('max-value')); const currentValue = parseInt(targetInput.val()) + 1; targetInput.val(currentValue).attr('value', currentValue).trigger('change'); wrapper.find(".minus").removeClass('disabled'); updateInputValue(targetModification, currentValue); if (currentValue >= maxValue) { element.addClass('disabled'); } } function decreaseOccupancyElement(clicked_element) { if (clicked_element.hasClass('disabled')) return; const wrapper = clicked_element.closest(".modification_buttons"); const targetInput = wrapper.find("input"); const targetModification = targetInput.attr('target'); const currentValue = parseInt(targetInput.val()) - 1; const minValue = parseInt(targetInput.attr('min-value')); wrapper.find(".plus").removeClass('disabled'); targetInput.val(currentValue).attr('value', currentValue).trigger('change'); updateInputValue(targetModification, currentValue); if (currentValue <= minValue) { clicked_element.addClass('disabled'); } } function updateInputValue(target, value) { $("*[name='" + target + "']").each(function () { const tagName = $(this).prop('tagName').toLowerCase(); if (tagName == 'select') { $(this).find("option").removeAttr('selected'); $(this).val(value); updateRoomsCapacity(); try { $(this).selectric("refresh"); } catch (e) { console.log("Error trying to refresh selectric"); } } else { $(this).val(value); } }); if (target == 'numRooms') { const occupancyWrapper = $("#occupancy_wrapper"); occupancyWrapper.find("[class^='room_num_']").each(function (index) { $(this).toggleClass('hide', index + 1 > value); }); } } function agesChecker(element) { const elementTarget = element.attr('target'); if (!elementTarget.includes('childrenRoom')) return; const currentValue = parseInt(element.attr('value')); const parentWrapper = element.closest('.guest_controll'); parentWrapper.find(".block_age_selection").each(function (index) { $(this).toggleClass('hide', index + 1 > currentValue); }); parentWrapper.find(".block_age_selection").removeClass('last') .filter(":not(.hide):last").addClass('last'); parentWrapper.find(".block_age_selection").each(function (index, element) { if (index + 1 <= currentValue) { $(element).removeClass('hide'); } else { $(element).addClass('hide'); } }); //parentWrapper.find(".block_age_selection").removeClass('last'); //parentWrapper.find(".block_age_selection:not(.hide):last").addClass('last'); } // Datepicker function datepickerConfigs() { DP_extend_info.config.booking_version = '7'; DP_extend_info.config.months_show = 2; DP_extend_info.config.custom_format_day_month = function (dateComponents) { dateComponents = dateComponents.split("/"); const month_short = $.datepicker._defaults['monthNamesShort'][parseInt(dateComponents[1], 10) - 1]; return "
" + dateComponents[0] + "
" + month_short + "
" + dateComponents[2] + "
"; }; DP_extend_info.config.show_callback = function () { $("body").addClass('datepicker_shown'); }; DP_extend_info.config.hide_callback = function () { $("body").removeClass('datepicker_shown'); }; DP_extend_info.config.short_days_names = true; $.i18n.dict["entry_date_select"] = $.i18n._("T_fechas"); $.i18n.dict["departure_date_select"] = $.i18n._("T_fechas"); $("label.dates_selector_label").html(`${$.i18n._("T_entrada")}${$.i18n._("T_salida")}`); }