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: "//oasishoteles-corpo-dot-oasishoteles.appspot.com", widget_url: "//oasishoteles-corpo-dot-oasishoteles.appspot.com/oasiswidget/", 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.51", "//oasishoteles-corpo-dot-oasishoteles.appspot.com/static_1/css/oasis_injection_styles/booking_widget_oasis_injection_styles.css?v=1.51", "//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.51", "https://cdn.paraty.es/static_files/common/css/datepicker.redmond/jquery-ui-1.8.16.custom.min.css?v=1.51" ], /*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.51")); break; case 'main_web_skeleton': dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/js/mainWebSkeletonAux_injection.js?v=1.51")); break; case 'selectric': dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/lib/selectric/jquery.selectric.1.8.js?v=1.51")); 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.51").then(function () { return bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/i18n/messages_" + lang + ".js?v=1.51").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.51"); bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/js/datepicker/jquery.ui.datepicker-" + lang + ".js?v=1.51").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-min.js?v=1.51").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); $("body").addClass('widget_fixed_header'); 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')); // Handle analytics info analytics_transfer_booking_process(); }; 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(); $('body').addClass('full_widget_paraty_open'); }); }; bookingWidgetController.close_widget = function () { $("i.fa-times.close_widget").click(function () { $("#widget_paraty").fadeOut(); $('body').removeClass('full_widget_paraty_open'); }); }; bookingWidgetController.bind_analytics_listeners = function () { let widget = $("#widget_paraty"); widget.find('.widget_buttons a.button').on('click auxclick', function (e) { let datalayer_name = $(this).attr('data-datalayer-name'); if (datalayer_name) { bookingWidgetController.send_datalayer_event({ event: 'book now', service: datalayer_name }); } }); $('#widget_paraty .destination_wrapper, .booking_steps .step_1').on('click', function () { bookingWidgetController.send_datalayer_event({ event: 'book now', service: 'hotel', title: 'paso 1' }); }); $('#widget_paraty .hotel_selector_inner li, .booking_steps .step_2').on('click', function () { if (!$(this).hasClass('current_step')) { let hotel_name = bookingWidgetController.get_selected_hotel_for_datalayer(); if (hotel_name) { bookingWidgetController.send_datalayer_event({ event: 'book now', service: 'hotel', title: 'paso 2', hotel: hotel_name }); } } }); $('.booking_steps .step_3').on('click', function () { if (!$(this).hasClass('current_step')) { let hotel_name = bookingWidgetController.get_selected_hotel_for_datalayer(), room_name = bookingWidgetController.get_selected_room_for_datalayer(), event_body = { event: 'book now', service: 'hotel', title: 'paso 3', hotel: hotel_name }; if (room_name) { event_body.room = room_name; } if (hotel_name) { bookingWidgetController.send_datalayer_event(event_body); } } }); widget.find(".wrapper_booking_button .submit_button").click(function () { if ($(".destination_fieldo input[name=destination]").val() !== "") { let hotel_name = bookingWidgetController.get_selected_hotel_for_datalayer(), room_name = bookingWidgetController.get_selected_room_for_datalayer(), occupancy = bookingWidgetController.get_selected_occupancy_for_datalayer(), promocode = $(this).closest('.wrapper_booking_button').find('.promocode_input').val(), event_body = { event: 'book now', service: 'hotel', title: 'paso 4', type: occupancy, hotel: hotel_name }; if (room_name) { event_body.room = room_name; } if (promocode) { event_body.coupon = promocode; } if (hotel_name) { bookingWidgetController.send_datalayer_event(event_body); } } }); }; bookingWidgetController.send_datalayer_event = function (data) { window.dataLayer = window.dataLayer || []; window.dataLayer.push(data); }; bookingWidgetController.get_selected_hotel_for_datalayer = function () { let widget = $("#widget_paraty"), selected_namespace = widget.find('#namespace').val(); if (!selected_namespace) { return } let datalayer_name = widget.find(`.hotel_selector .hotel_selector_option.${selected_namespace}`).attr('data-datalayer-name'); if (datalayer_name) { return datalayer_name; } else { return ''; } }; bookingWidgetController.get_selected_room_for_datalayer = function () { let widget = $("#widget_paraty"), room_name = widget.find('#calendar-app-root .filter_selector .selector_label').text(), room_options = []; widget.find('#calendar-app-root .filter_selector .selector .option').each(function () { let option_text = $(this).text(); if (option_text) { room_options.push(option_text); } }); if (room_options.includes(room_name)) { return room_name.toLowerCase(); } else { return ''; } }; bookingWidgetController.get_selected_occupancy_for_datalayer = function () { let widget = $("#widget_paraty"), num_rooms = widget.find('.booking_form [name="numRooms"]').val(), occupancies = []; if (num_rooms) { num_rooms = parseInt(num_rooms); for (let i = 1; i <= num_rooms; i++) { let room_wrapper = widget.find(`.room_list .room${i}`), adults = room_wrapper.find(`#adultsRoom${i}`).val(), kids = room_wrapper.find(`#childrenRoom${i}`).val(), babies = room_wrapper.find(`#babiesRoom${i}`).val(), occupancy_string = adults; if (kids) { let number = parseInt(kids); if(!number) $(".children_selector").toggleClass("desactivate") occupancy_string += `,${kids}`; } if (babies) { occupancy_string += `,${babies}`; } occupancies.push(occupancy_string); } return occupancies.join(';'); } return ''; }; bookingWidgetController.custom_functions = function () { $(window).scroll(function () { var scrollHeight = $(window).height(); if ($(window).scrollTop() >= scrollHeight) { $('body, #widget_paraty').addClass('scrolled'); } else { $('body, #widget_paraty').removeClass('scrolled'); } }); let widget = $("#widget_paraty"); 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(); $(window).on('popstate', function () { hotel_preselected(); }); $("#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.attr('data-hotel-preselection'); if (hotel_preselection) { $("#widget_paraty .hotel_selector_option#" + hotel_preselection).click(); } let custom_source = widget.attr('data-source'); if (custom_source) { let source_input = $('').val(custom_source); widget.find('.paraty-booking-form').prepend(source_input); } individual_hotel_personalization(); bookingWidgetController.bind_analytics_listeners(); }; function hotel_preselected() { let url = window.location.href; let individual_hotel_url = url.substring(url.lastIndexOf('/') + 1); let hotel_namespace = ''; let hotel_equivalencies = $(".hotel_selector .hotel_selector_option"); if(hotel_equivalencies.length){ hotel_equivalencies.each(function(){ let preselectedHotel = $(this).attr("data-hotel-preselected"); if(preselectedHotel == individual_hotel_url){ hotel_namespace = $(this).attr("id"); $(this).toggleClass('selected') } }) } if (hotel_namespace) { let widget = $("#widget_paraty"); $('#widget_paraty #namespace').val(hotel_namespace); $("#widget_paraty .hotel_selector_option").each(function () { let hotel_id = $(this).attr('id'); let hotel_title_selector = $(this).find('.title_selector').html(); let new_placeholder_html = hotel_title_selector.replace("
", " ").replace("&", "&").replace(/<.*?>/g, "") if (hotel_namespace === hotel_id) { $('#widget_paraty .destination').attr('placeholder', new_placeholder_html); $("#widget_paraty .destination_fieldo input[name=destination]").val(new_placeholder_html); url_booking = widget.find("#url_booking_" + hotel_id).val(), hotel_value = url_booking.indexOf('http') > -1 ? url_booking : "https://" + hotel_id + url_booking; window.calendar_data.update_namespace_calendar(hotel_id); $('.price_calendar_wrapper .toggle_chart').css('opacity', '1').css('pointer-events', 'auto'); } }) } } 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'); } setTimeout(function (){load_new_room_dates();},0) }; } function prepare_guests_selector(reloaded=false) { $("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(); }); if (!reloaded) { $(".remove_room_element").click(function () { const current_room_numbers = $("select.rooms_number").val(); if (current_room_numbers > 1) { const target_room_number = parseInt(current_room_numbers) - 1; $("select.rooms_number option").removeAttr('selected'); $("select.rooms_number option[value='" + target_room_number + "']").attr('selected', 'selected'); $(".room" + current_room_numbers).hide(); $("select.rooms_number").val(target_room_number); $("select.rooms_number").selectric("refresh"); } set_occupancy_number(); }); const close_btn = "
"; const close_calendar_btn = "
"; $(".room_list_wrapper").append(close_btn); $(".calendar_root_wrapper").append(close_calendar_btn); $(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"); }); const booking_btn = "
" + "" + "
"; $(".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(); }); } const add_room_html = "
" + $.i18n._('T_add_new_room') + "
"; const remove_room_html = "
" + $.i18n._('T_remove_room') + "
"; $(".room_list_wrapper .room_list .room").not(':last').each(function () { $(this).append(add_room_html); }); $(".room_list_wrapper .room_list .room").not(':first').each(function () { $(this).append(remove_room_html); $(this).css('display', 'none'); }); $(".add_room").click(add_room); $(".remove_room").click(remove_room); $(".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) { const selectric_element = element.closest(parent_class).find(select); const label_for = element.closest(".range_label_enabled"); const selectric_val = parseInt(selectric_element.val()); if (selectric_val > min && selectric_val < max) { const 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 < $("select.rooms_number option").length) { $($(".selectric-rooms_number .selectricItems li").get(number_rooms)).trigger("click"); set_occupancy_number(); } $(".room" + number_rooms + " .add_room").hide(); $(".room" + number_rooms + " .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(); } $(".room" + (number_rooms-1) + " .add_room").show(); $(".room" + (number_rooms-1) + " .remove_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 (babies_number) { placeholder_string += +"-" + babies_number; } placeholder_string += ""; 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(); setTimeout(function () { $("#widget_paraty").addClass("initialized") }, 300); }; 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"); 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); //Update rooms to select update_valid_rooms_options($(this), widget); set_occupancy_number() }); $(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 update_valid_rooms_options(hotel_selected, widget) { const valid_rooms = hotel_selected.data('valid-rooms'); if (!valid_rooms) return; const props_to_change = ['for', 'id', 'name', 'class']; const exclude_selectors_to_change = ['.range-age', 'option']; const room_list = widget.find('ul.room_list'); const rooms = room_list.find('li.room'); const first_room = rooms.first(); const button_search = room_list.find('.wrapper_booking_button_guest'); const rooms_number_selector = widget.find('.rooms_number_wrapper select.rooms_number'); rooms_number_selector.selectric('destroy'); first_room.find('.add_room').remove(); first_room.find('.remove_room').remove(); first_room.find('select').selectric('destroy'); const reference_room = first_room.clone(true); const reference_button_search = button_search.first().clone(true); rooms.remove(); button_search.remove(); rooms_number_selector.find('option').remove(); for (const room_number of valid_rooms.split(';')) { const current_room_element = reference_room.clone(true); current_room_element.find('*').addBack().each(function() { const exclude_element = exclude_selectors_to_change.some(selector => $(this).closest(selector).length); if (exclude_element) return; for (const prop of props_to_change) { const attr_value = $(this).attr(prop); if (attr_value && attr_value.includes('1')) { $(this).attr(prop, attr_value.replace(/1/g, room_number)); } } //if ($(this).hasClass('range-age') || $(this).parent().hasClass('range-age')) return; $(this).contents().filter((_, node) => node.nodeType === Node.TEXT_NODE).each(function() { this.nodeValue = this.nodeValue.replace(/1/g, room_number); }); }); const option = $(document.createElement('option')); option.val(`${room_number}`).text(`${room_number}`); rooms_number_selector.append(option); current_room_element.removeClass('room1').addClass(`room${room_number}`); current_room_element.find('select').selectric({ disableOnMobile: false }); room_list.append(current_room_element); } rooms_number_selector.selectric({disableOnMobile: false}) room_list.append(reference_button_search); prepare_guests_selector(true); } function individual_hotel_personalization() { const url_host = window.location.host, individuals_url = { "the-pyramid-at-grand-cancun.com": "oasishoteles-pyramid", "grand-oasis-cancun.com": "oasishoteles-grandcancun", "grand-oasis-palm.com": "oasishoteles-grandpalm", "thesenscancun.com": "oasishoteles-senscancun", "oasis-palm.com": "oasishoteles-oasispalm", "smart-cancun.com": "oasishoteles-smart", "oh-cancun.com": "oasishoteles-ohurban", "grand-oasis-tulum.com": "oasishoteles-tulum", 'localhost:6547': 'oasishoteles-tulum' } if (url_host !== "oasishoteles.com" && url_host !== 'viajescaribemaya.com' && url_host !== 'localhost' && url_host !== 'staging.oasishoteles.com' && url_host !== 'oasishoteles.dev') { $("#widget_paraty").addClass("not_corpo"); $(window).scroll(function () { if ($(window).scrollTop() > 0) { $("#widget_paraty").addClass("fixed"); } else { $("#widget_paraty").removeClass("fixed"); } }); if (url_host in individuals_url) { let option = $("#widget_paraty .hotel_selector_option#" + individuals_url[url_host]); select_hotel_selector(option); $(".booking_steps .step_1").hide(); $(".room_list_wrapper .room_list .hotel_name_rooms").hide(); } } } function select_hotel_selector(option) { let widget = $("#widget_paraty"); widget.find(".hotel_selector").hide("fast"); widget.find(".hotel_selector_option").removeClass("selected"); option.addClass("selected"); let new_placeholder_html = option.find(".title_selector").html().replace("
", " ").replace("&", "&").replace(/<.*?>/g, ""), id_hotel_4_url = option.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); widget.find("form").attr("action", hotel_value).find("#namespace").val(new_namespace); } function create_cookie_oasis_injection(key, valor){ document.cookie= key + "=" + valor; } function search_cookie_oasis_injection(key){ var encontrado = -1; var x = document.cookie; if (x) { var y = x.split(";"); for (var i=0;i< y.length; i++) { encontrado = y[i].search(key); if (encontrado > -1) { resultado = y[i].split("="); return resultado[1]; } } } } function delete_cookie_oasis_injection(key){ document.cookie = key + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;'; } function get_url_parameter(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]; } } } function analytics_transfer_booking_process() { var gclid = get_url_parameter('gclid'); if (gclid){ create_cookie_oasis_injection('gclid', gclid); } else { gclid = search_cookie_oasis_injection('gclid'); } if (gclid){ //by name! set value in ALL forms $('input[name="gclid"]').val(gclid); } } bookingWidgetController.init(); $(document).ready(function (){ let originalPushState = history.pushState; history.pushState = function() { originalPushState.apply(history, arguments); hotel_preselected(); }; })