if (typeof jQuery != "undefined") $ = jQuery;
var bookingWidgetController = function () {
return {
config: {
language: $("html").attr("lang") ? $("html").attr("lang").replace(/-.*/, '') : $("html").attr("xml:lang").replace(/-.*/, ''),
base_url: "//molinodelarco-dot-secure-booking42.appspot.com",
widget_url: "//molinodelarco-dot-secure-booking42.appspot.com/paraty-widget-injection/",
only_adults: "",
hide_my_bookings: false,
widget_in_page: false,
widget_target: "",
dependcencies_added: typeof(bookingWidgetController) == "undefined" ? false : bookingWidgetController.config.dependcencies_added,
datepicker_added: false,
css_list : [
"https://cdn.paraty.es/static_files/common/plugins/dates-selector/css/datepicker_ext_inf.css?v=1.49",
"//molinodelarco-dot-secure-booking42.appspot.com/paraty-injection-styles?version=v1",
"//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.49",
"https://cdn.paraty.es/static_files/common/css/datepicker.redmond/jquery-ui-1.8.16.custom.min.css?v=1.49"
]
},
init: function () {
this.update_local_configs();
this.prepare_dependencies();
},
update_local_configs: function() {
if (typeof (paraty_booking_options) !== 'undefined') {
for (var key_config in paraty_booking_options) {
this.config[key_config] = paraty_booking_options[key_config];
}
}
},
prepare_dependencies: function () {
let base_url = bookingWidgetController.config.base_url,
lang = bookingWidgetController.config.language;
if (!bookingWidgetController.config.dependcencies_added) {
$.getScript(`https://cdn.paraty.es/static_files/common/lib/jquery-ui-1.10.1.custom.min.modified.js?v=1.49`).done(function () {
$.getScript(`https://cdn.paraty.es/static_files/common/js/mainWebSkeletonAux_injection.js?v=1.49`);
$.getScript(`https://cdn.paraty.es/static_files/common/lib/selectric/jquery.selectric.1.8.js?v=1.49`).done(function () {
$.getScript(`https://cdn.paraty.es/static_files/common/lib/jquery-i18n-1.1.1/jquery.i18n.js?v=1.49`).done(function () {
$.getScript(`https://cdn.paraty.es/static_files/common/i18n/messages_${lang}.js?v=1.49`).done(function () {
$.i18n.load(messages);
bookingWidgetController.get_booking_widget_html();
bookingWidgetController.config.dependcencies_added = true;
});
});
});
});
}
},
get_booking_widget_html: function () {
bookingWidgetController.load_css();
let 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.click_listeners();
bookingWidgetController.create_link_booking();
//TODO: Use only in case that has hotel selector
paratyHotelSelector.init();
});
},
load_css: function () {
let list_css = bookingWidgetController.config.css_list;
for (let i = 0; i < list_css.length; i++) {
$('head').append($('').attr('href', list_css[i]));
}
},
add_widget_html: function() {
let paraty_widget = bookingWidgetController.config.widget_html,
widget = $("#widget_paraty"),
widget_custom_target = bookingWidgetController.config.widget_target,
custom_target_exist = false;
if (!widget.length){
widget = $("");
if (!widget_custom_target || !$(`${widget_custom_target}`).length) {
$("body").append(widget);
} else {
$(`${widget_custom_target}`).append(widget);
custom_target_exist = true;
}
}
if(widget.length) {
widget.html(paraty_widget);
if (!bookingWidgetController.config.widget_in_page || !custom_target_exist ) {
widget.addClass("popup");
} else {
$("#widget_paraty").addClass("in_page");
}
if (!bookingWidgetController.config.hide_my_bookings) {
$("#widget_paraty .booking_form_title").append($(".cancel_booking_link")).addClass("with_cancel");
}
}
},
add_button_mobile_version_html: function() {
$("#widget_paraty").append($("").html($.i18n._("reserva_ahora")));
$("#widget_paraty #full_wrapper_booking").append($(""));
},
load_datepicker: function () {
let lang = bookingWidgetController.config.language,
base_url = bookingWidgetController.config.base_url;
// Refactor in a external function
if (!bookingWidgetController.config.datepicker_added) {
$.getScript(`https://cdn.paraty.es/static_files/common/plugins/pricescalendar/calendar.plugin.js?v=1.49`);
$.getScript(`https://cdn.paraty.es/static_files/common/js/datepicker/jquery.ui.datepicker-${lang}.js?v=1.49`).done(function () {
$.getScript(`https://cdn.paraty.es/static_files/common/plugins/dates-selector/datepicker_v1.js`).done(function () {
_set_datepicker_regional($);
bookingWidgetController.datepicker_configuration();
$.getScript(`https://cdn.paraty.es/static_files/common/scripts/booking_7.js?v=1.49`).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();
},
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("/");
let 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) {
$(element).text($(element).text() );
});
$("select.rooms_number").selectric("refresh");
},
set_occupancy_number: function () {
let number_of_rooms = $("select[name='numRooms']").val(),
adults_number = 0,
kids_number = 0,
babies_number = 0;
if (number_of_rooms) {
for (let room_loop = 1; room_loop <= number_of_rooms; room_loop++) {
let 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);
}
}
let target_placeholder = $(".guest_selector .placeholder_text"),
placeholder_string = bookingWidgetController.occupancy_format_html();
let room_tag = number_of_rooms === 1 ?
bookingWidgetController.config.room_tag : bookingWidgetController.config.rooms_tag;
let adult_tag = adults_number === 1 ?
bookingWidgetController.config.adult_text : bookingWidgetController.config.adults_text;
let kid_tag = kids_number === 1 ?
bookingWidgetController.config.kid_text : bookingWidgetController.config.kids_text;
let 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() {
let occupancy_string = '';
if (this.config.only_adults) {
occupancy_string = "@@N_R@@ @@T_R@@, @@N_A@@";
} else {
occupancy_string = "@@N_R@@ @@T_R@@, @@N_A@@-@@N_C@@";
}
return occupancy_string;
},
open_widget: function () {
if ($("#widget_paraty").hasClass("in_page") && !$("#floating_button").is(":visible")) {
$([document.documentElement, document.body]).animate({
scrollTop: $("#widget_paraty").offset().top - 131
}, 2000);
} else {
$("#full_wrapper_booking").fadeToggle();
$("#floating_button").addClass("hidden");
}
},
close_widget: function () {
$("#full_wrapper_booking").fadeOut();
$("#floating_button").removeClass("hidden");
},
click_listeners: function () {
$("html").click(function (event) {
let event_target = $(event.target);
if (!event_target.closest(".room_list_wrapper").length && !event_target.closest(".guest_selector").length) {
$(".room_list_wrapper").slideUp();
}
});
$("#floating_button_paraty, #floating_button").click(function () {
bookingWidgetController.open_widget();
});
$("#widget_paraty .close_widget").click(function () {
bookingWidgetController.close_widget();
});
},
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();
},
add_rooms: function() {
let number_rooms = parseInt($("select.rooms_number").val());
if (number_rooms < 3) {
$($(".rooms_number_wrapper .selectricItems li").get(number_rooms)).trigger("click");
bookingWidgetController.set_occupancy_number();
}
},
remove_room: function() {
let number_rooms = parseInt($("select.rooms_number").val());
if (number_rooms > 1) {
$($(".rooms_number_wrapper .selectricItems li").get(number_rooms - 2)).trigger("click");
bookingWidgetController.set_occupancy_number();
}
},
custom_functions: function(){
let add_room_html = ""+$.i18n._("T_anadir")+"
"+$.i18n._("T_eliminar")+"
";
$(".room_list_wrapper").append(add_room_html);
$(".room_list_wrapper").on("click", ".add_room", bookingWidgetController.add_rooms);
$(".room_list_wrapper").on("click", ".remove_room", bookingWidgetController.remove_room);
bookingWidgetController.config.languages = {
"es": "SPANISH",
"en": "ENGLISH",
};
$(window).on("load", function() {
bookingWidgetController.prepare_guest_selector();
let selected_namespace = $("#paraty_widget_namespace").val();
if (selected_namespace) {
setTimeout(function () {
$(".hotel_selector .hotel_selector_option#" + selected_namespace).trigger("click");
$(".hotel_selector .destiny").hide();
$(".hotel_selector .hotel_selector_option#" + selected_namespace).closest(".destiny").show();
}, 3000);
}
});
setTimeout(function () {
let open_widget_param = bookingWidgetController.get_url_parameters('open_widget');
if (open_widget_param) {
bookingWidgetController.open_widget();
}
}, 2000)
$(".destination_wrapper, .close_hotel_selector").unbind("click");
$(".destination_wrapper, .close_hotel_selector").click(function () {
$(".hotel_selector").slideToggle();
});
},
get_url_parameters: 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];
}
}
},
create_link_booking: function() {
try {
let link_booking = bookingWidgetController.config.base_url + "/booking1?numRooms=1&adultsRoom1=2" +
"&adultsRoom2=0&adultsRoom3=0&childrenRoom1=0&childrenRoom2=0&childrenRoom3=0&babiesRoom1=0&" +
"babiesRoom2=0&babiesRoom3=0&fromCountry=&language=" +
bookingWidgetController.config.languages[bookingWidgetController.config.language];
$(".paraty-booking-link").each(function(){
$(this).attr("href", link_booking);
});
} catch(error) {
console.log("[Paraty Widget] Error trying to get the utl to booking engine");
}
},
}
}();
paratyHotelSelector = function() {
return {
init: function() {
this.bind_listeners();
},
bind_listeners: function() {
$(".search_hotels_selector").keyup(function () {
paratyHotelSelector.searchHotelElementInput($(this));
});
$(".booking_0_hotel_custom_selection").click(function(){
paratyHotelSelector._custom_set_all_hotels_search($(this));
});
$(".hotel_selector li").click(function () {
let hotel_name = $(this).find(".title_selector").html();
$(".destination_wrapper .destination_field .destination").html(hotel_name);
});
last_form_class_wrapper = '';
//TODO: This continue working ,is needed?
$(".hotel_selector .hotel_selector_option").click(function () {
_hotel_selection($(this));
if ($("#floating_button").is(":visible")) {
let hotel_selected = $(this).text();
$(".search_title").text(hotel_selected);
$(".hotel_selector .hotel_selector_option").removeClass("selected");
$(this).addClass("selected");
} else {
let destination = $("#widget_paraty .destination"),
placeholder_text = destination.attr("placeholder").trim().replace(/ *\([^)]*\) */g, "");
destination.attr("placeholder", placeholder_text);
$(".hotel_selector").slideUp();
setTimeout(function () {
let dest_value = $(".destination").attr("value");
$(".destination").html(dest_value);
}, 1000)
}
//Form class wrapper
let form_class_wrapper = $(this).attr('form_class');
if (last_form_class_wrapper) {
$(".submit_button").removeClass(last_form_class_wrapper);
}
if (form_class_wrapper) {
last_form_class_wrapper = form_class_wrapper;
$(".submit_button").addClass(form_class_wrapper);
}
setTimeout(function () {
$(".paraty-booking-form").each(function () {
let submit_button = $(this).find(".submit_button");
if (!submit_button.is(':visible') || submit_button.attr('disabled')) {
submit_button.trigger('click');
}
})
}, 1000)
});
},
searchHotelElementInput: function(){
let searched_hotel = $(".search_hotels_selector").val();
$(".hotel_selector .hotel_selector_inner .destiny .hotel_selector_destiny li").each(function(){
let actual_html = $(this).html();
actual_html = actual_html.toLowerCase();
searched_hotel = searched_hotel.toLowerCase();
if(actual_html.indexOf(searched_hotel) < 0){
$(this).css('display', 'none');
$(this).closest('.destiny').children('h3').css('display', 'none');
}else{
$(this).css('display', 'block');
$(this).closest('.destiny').children('h3').css('display', 'block');
}
if(searched_hotel == ""){
$(this).css('display', 'block');
$(this).closest('.destiny').children('h3').css('display', 'block');
}
});
},
_custom_set_all_hotels_search: function(clicked_element) {
let all_namespaces = clicked_element.attr('namespaces'),
hotel_name = clicked_element.attr('hotel_name'),
hotel_url = clicked_element.attr('hotel_url');
$(".paraty-booking-form").each(function () {
$(this).attr('action', hotel_url);
let placeholder_text = hotel_name.trim().replace(/ *\([^)]*\) */g, "");
$(this).find(".destination").val(hotel_name).attr("placeholder", placeholder_text).html(placeholder_text);
if (!$(this).find("input[name='applicationIds']").length) {
var application_ids_input = $("");
application_ids_input.attr('value', all_namespaces);
application_ids_input.appendTo($(this));
} else {
$(this).find("input[name='applicationIds']").val(all_namespaces);
}
});
$(".hotel_selector").slideUp();
},
}
}();
bookingWidgetController.init();