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: "//vidamar-villas-dot-vidamar-resorts.appspot.com", widget_url: "//vidamar-villas-dot-vidamar-resorts.appspot.com/vidamarwidget/", only_adults: "", dependcencies_added: typeof(bookingWidgetController) == "undefined" ? false : bookingWidgetController.config.dependcencies_added, datepicker_added: false, css_list : [ "//vidamar-villas-dot-vidamar-resorts.appspot.com/static_1/plugins/dates-selector/css/datepicker_ext_inf.css?v=1.30", "//vidamar-villas-dot-vidamar-resorts.appspot.com/static_1/css/vidamar/booking_widget_vidamar.css?v=1.30", "//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css", "//vidamar-villas-dot-vidamar-resorts.appspot.com/static_1/plugins/pricescalendar/styles.css?v=1.30", "//vidamar-villas-dot-vidamar-resorts.appspot.com/static_1/css/datepicker.redmond/jquery-ui-1.8.16.custom.min.css?v=1.30" ], /*Special configs*/ avoid_guest_autoclose_click: false }, init: function () { this.prepare_dependencies(); }, prepare_dependencies: function () { var base_url = bookingWidgetController.config.base_url, lang = bookingWidgetController.config.language; if (!bookingWidgetController.config.dependcencies_added) { $.getScript(base_url + "/static_inj/lib/jquery-ui-1.10.1.custom.min.modified.js?v=1.30").done(function () { $.getScript(base_url + "/static_1/js/mainWebSkeletonAux_injection.js?v=1.30"); $.getScript(base_url + "/static_1/lib/selectric/jquery.selectric.1.8.js?v=1.30").done(function () { $.getScript(base_url + "/static_1/lib/jquery-i18n-1.1.1/jquery.i18n.js?v=1.30").done(function () { $.getScript(base_url + "/static_1/i18n/messages_" + lang + ".js?v=1.30").done(function () { $.i18n.load(messages); 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(); }); }, 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) { $.getScript(base_url + "/static_1/plugins/pricescalendar/calendar.plugin.js?v=1.30"); $.getScript(base_url + "/static_1/js/datepicker/jquery.ui.datepicker-" + lang + ".js?v=1.30").done(function () { $.getScript(base_url + "/static_1/plugins/dates-selector/datepicker_v1.js").done(function () { _set_datepicker_regional($); bookingWidgetController.datepicker_configuration(); $.getScript(base_url + "/static_1/scripts/booking_7.js?v=1.30").done(function () { bookingWidgetController.after_load_booking_script(); bookingWidgetController.custom_functions(); bookingWidgetController.config.datepicker_added = true }); }); }); } }, after_load_booking_script: function() { _set_datepicker_regional($); $(".room_selector").selectric({disableOnMobile: false}); $(".rooms_number").selectric({disableOnMobile: false}); DP_extend_info.init(); bookingWidgetController.prepare_guest_selector(); bookingWidgetController.adding_room_tag_selector(); bookingWidgetController.set_occupancy_number(); bookingWidgetController.update_date_by_timezone(); }, 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); }); $("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(); }, custom_functions: function(){ } }; }(); bookingWidgetController.add_widget_html = function () { var paraty_widget = $("
").html(bookingWidgetController.config.widget_html); if($(".paraty-widget-wrapper").length) { $(".paraty-widget-wrapper").html(paraty_widget); } }; bookingWidgetController.custom_format_date = function(dateComponents) { dateComponents = dateComponents.split("/"); var month_names = $.datepicker._defaults.monthNamesShort, 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]); }; bookingWidgetController.occupancy_format_html = function() { return "@@N_A@@/@@N_C@@/@@N_B@@"; }; bookingWidgetController.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(); placeholder_string = placeholder_string.replace("@@N_A@@", adults_number).replace("@@N_C@@", kids_number).replace("@@N_B@@", babies_number); target_placeholder.html(placeholder_string); }; bookingWidgetController.adding_room_tag_selector = function() { return false; }; bookingWidgetController.load_datepicker = function () { var lang = bookingWidgetController.config.language, base_url = bookingWidgetController.config.base_url; bookingWidgetController.get_namespace_widget(); $("body").addClass("vidamar-villas"); $.getScript(base_url + "/static_1/plugins/pricescalendar/calendar.plugin.js?v=1.30"); $.getScript(base_url + "/static_1/js/datepicker/jquery.ui.datepicker-" + lang + ".js?v=1.30").done(function () { $.getScript(base_url + "/static_1/plugins/dates-selector/datepicker_v1.js").done(function () { _set_datepicker_regional($); bookingWidgetController.datepicker_configuration(); if (bookingWidgetController.config._custom_hotel_domain){ DP_extend_info.config.hotel_path_endpoint = bookingWidgetController.config._custom_hotel_domain; } $.getScript(base_url + "/static_1/scripts/booking_7.js?v=1.30").done(function () { bookingWidgetController.after_load_booking_script(); bookingWidgetController.custom_functions(); }); }); }); }, bookingWidgetController.floating_widget = function(){ var actual_position = $(window).scrollTop(), widget = $("#widget_paraty"), floating_props = bookingWidgetController.get_slider_height(), slider_height = floating_props[0], floating_extra_class = floating_props[1], widget_position = slider_height; if (actual_position >= widget_position && !widget.hasClass("floating_widget")) { widget.addClass("floating_widget " + floating_extra_class); } else if (actual_position < widget_position && widget.hasClass("floating_widget")) { widget.removeClass("floating_widget " + floating_extra_class); } }; bookingWidgetController.open_widget = function () { $("#floating_button").click(function () { $("#full_wrapper_booking").fadeToggle(); }); }; bookingWidgetController.custom_functions = function () { $(window).load(function() { bookingWidgetController.floating_widget(); }); if ($("#full_wrapper_booking .hotel_selector_option").length) { $("#widget_paraty").addClass("with_hotel_selector"); $("#full_wrapper_booking .hotel_selector_option").click(function () { _hotel_selection($(this)); }); $("#full_wrapper_booking .destination_field").click(function () { $("#full_wrapper_booking .hotel_selector").slideToggle(); }); if (bookingWidgetController.config._custom_hotel_namespace) { $("#" + bookingWidgetController.config._custom_hotel_namespace).trigger('click'); $("#widget_paraty").removeClass("with_hotel_selector").addClass("hide_hotel_selector"); } $(document).mouseup(function (e) { var container = $("#full_wrapper_booking .destination_field"); if(!container.is(e.target) && container.has(e.target).length === 0) { $('#full_wrapper_booking .hotel_selector').slideUp(); } }); } $(window).scroll(bookingWidgetController.floating_widget); }; bookingWidgetController.get_slider_height = function() { if ($(".site_wrapper .page_title3").length) { return [$(".site_wrapper .page_title3").first().outerHeight(), "vidamar-villas"]; } else if (window.location.href.indexOf('salgadosbeachvillas.pt') > -1) { return [9999999, "vidamar-villas"]; } else if ($("header.header-company").length) { return [$("header.header-company").outerHeight(), "vidamar-sao-rafael"]; } else if ($(".logo-section").length) { if ($(".slidermar").length) { return [$(".logo-section").first().outerHeight() + $(".slidermar").first().outerHeight(), "vidamar-corporate"]; } else { return [$(".logo-section").first().outerHeight(), "vidamar-corporate-inner"]; } } else { return [100, "vidamar"]; } }; bookingWidgetController.get_namespace_widget = function() { var paraty_widget_namespace = $("#paraty_widget_namespace"), paraty_widget_internal_url = $("#paraty_widget_url"); if (paraty_widget_namespace.length){ this.config._custom_hotel_namespace = paraty_widget_namespace.val(); this.config._custom_hotel_domain = paraty_widget_internal_url.val(); } }; bookingWidgetController.init();