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: "//soho-corpo-dot-soho-boutique-hotels.appspot.com",
widget_url: "//soho-corpo-dot-soho-boutique-hotels.appspot.com/sohosignaturewidget/",
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.13",
"//soho-corpo-dot-soho-boutique-hotels.appspot.com/static_1/css/soho/booking_widget_soho.css?v=1.13",
"//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.13",
"https://cdn.paraty.es/static_files/common/css/datepicker.redmond/jquery-ui-1.8.16.custom.min.css?v=1.13"
],
/*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.13"));
break;
case 'main_web_skeleton':
dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/js/mainWebSkeletonAux_injection.js?v=1.13"));
break;
case 'selectric':
dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/lib/selectric/jquery.selectric.1.8.js?v=1.13"));
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.13").then(function () {
return bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/i18n/messages_" + lang + ".js?v=1.13").then(function () {
$.i18n.load(messages);
});
}));
break;
case 'flight_hotel_controller':
dependenciesToLoad.push(bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/js/flight_hotel/flight_hotel_controller.js?v=1.13"));
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 (typeof FlightHotelWidgetController != "undefined") {
FlightHotelWidgetController.config.baseUrl = '//soho-corpo-dot-soho-boutique-hotels.appspot.com';
FlightHotelWidgetController.init();
}
if ($("#add_analytics_campaings_tracking") && $("#add_analytics_campaings_tracking").length > 0) {
try {
bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/scripts/booking_process/analytics/booking_utm_controller.js?v=1.13")
} catch (e) {
console.error("Error loading booking_utm_controller.js", e);
}
}
});
},
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.13");
bookingWidgetController._getScript("https://cdn.paraty.es/static_files/common/js/datepicker/jquery.ui.datepicker-" + lang + ".js?v=1.13").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.13").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(){
}
};
}();
bookingWidgetController.add_widget_html = function () {
var paraty_widget = bookingWidgetController.config.widget_html;
if($("#widget_paraty").length) {
$("#widget_paraty").html(paraty_widget);
$("#widget_paraty #full_wrapper_booking .booking_form_title").append($(".cancel_booking_link"));
if ($(window).width() < 1000) {
$("#widget_paraty #full_wrapper_booking").hide();
}
}
};
bookingWidgetController.custom_format_date = function (dateComponents) {
dateComponents = dateComponents.split("/");
var month_names = $.datepicker._defaults.monthNames,
target_month = parseInt(dateComponents[1], 10) - 1,
html_date = "%d
/%m
/%y
";
return html_date.replace("%d", dateComponents[0]).replace("%m", dateComponents[1]).replace("%y", dateComponents[2]);
};
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 () {
if ($("#floating_button_paraty").length) {
$("#floating_button").addClass("hidden");
}
$("#floating_button_paraty, #floating_button").click(function () {
$("#full_wrapper_booking").fadeToggle();
$(".with_paraty_widget").addClass("active");
});
$(".close_widget").click(function () {
$(".with_paraty_widget").removeClass("active");
});
};
bookingWidgetController.floating_widget = function(){
var actual_position = $(window).scrollTop(),
widget = $("#widget_paraty"),
slider_height = 500,
widget_difference = $("body").length ? widget.outerHeight() : 0,
widget_position = slider_height - widget_difference;
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.custom_functions = function () {
bookingWidgetController.config.languages = {
"es": "SPANISH",
"en": "ENGLISH",
};
try {
create_link_booking();
} catch(error) {
console.log("[Paraty Widget] Error trying to get the utl to booking engine");
}
bookingWidgetController.floating_widget();
bookingWidgetController.prepare_guest_selector();
hotel_selector_controller();
$("#widget_paraty").addClass('corp');
$(window).scroll(bookingWidgetController.floating_widget);
$("#full_wrapper_booking .children_selector select.room_selector").change(function () {
check_kids_ages($(this));
});
if ($("#booking").length) {
$("#full_wrapper_booking .kidAgesSelect").selectric();
}
};
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 create_link_booking() {
var 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];
var paraty_links = $("a.paraty-booking-link, a[href*='app.thebookingbutton.com']");
paraty_links.each(function(){
$(this).attr("href", link_booking).removeAttr("target");
});
}
function paraty_perform_search() {
$(".paraty-booking-form .submit_button").trigger('click');
}
function hotel_selector_controller() {
// Based on Ona: Corp selector
let widget = $("#widget_paraty"),
booking_form = widget.find('.booking_form'),
hotel_preselection = widget.attr('data-hotel-namespace');
widget.find(".destination_wrapper").on('click', function(){
widget.find(".close_button_datepicker").click();
widget.find(".hotel_selector").slideDown();
widget.find("#full_wrapper_booking").addClass("fixed");
});
widget.find(".destiny_selector_inner .destiny a").click(function(e){
e.preventDefault();
$(this).parent().toggleClass("active");
});
widget.find(".hotel_selector_option").click(function () {
widget.find(".hotel_selector").hide("fast");
widget.find("#full_wrapper_booking").removeClass("fixed");
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,
kids_age_start = $(this).data('kids_age_start'),
kids_age_end = $(this).data('kids_age_end'),
only_adults = $(this).data('only_adults');
//change the value
widget.find(".destination").val(new_placeholder_html);
booking_form.attr("action", hotel_value).find("#namespace").val(new_namespace);
if (kids_age_start !== "" && kids_age_end !== "") {
widget.find('.children_selector .range-age').text(kids_age_start + "-" + kids_age_end + " " + $.i18n._("T_anyos"))
}
if (only_adults) {
widget.find('.children_selector').hide();
widget.find('.babies_selector').show();
widget.find('.guest_selector .placeholder_text .kids').hide();
widget.find('.guest_selector .placeholder_text .babies').show();
} else {
widget.find('.children_selector').show();
widget.find('.babies_selector').hide();
widget.find('.guest_selector .placeholder_text .kids').show();
widget.find('.guest_selector .placeholder_text .babies').hide();
}
});
widget.find(".destiny_selector_inner .destiny .booking_0_destiny").click(function(){
let all_namespaces = $(this).attr('namespaces'),
hotel_name = $(this).attr('hotel_name');
widget.find(".hotel_selector").slideUp();
booking_form.attr("action", "//soho-corpo-dot-soho-boutique-hotels.appspot.com/booking0");
booking_form.find(".destination").val(hotel_name);
if (!booking_form.find("input[name='applicationIds']").length) {
$("").appendTo(booking_form);
}
booking_form.find("input[name='applicationIds']").val(all_namespaces);
});
widget.find(".hotel_selector .close").click(function(e){
e.preventDefault();
widget.find(".hotel_selector").slideUp();
widget.find("#full_wrapper_booking").removeClass("fixed");
});
widget.find(".hotel_selector_filter .destiny_filter").click(function(e){
e.preventDefault();
var to_show = $(this).attr("data-destiny");
widget.find(".hotel_selector_filter .destiny_filter").removeClass("selected");
widget.find(".destiny_selector_inner, .hotel_selector_inner").removeClass("active");
$(this).addClass("selected");
widget.find("."+to_show).addClass("active");
});
widget.find(".hotel_selector_search input").keydown(function () {
setTimeout(function(){
searchHotelElement();
}, 100);
}).focus(function () {
widget.find(".hotel_selector_filter .destiny_filter").removeClass("selected");
widget.find(".destiny_selector_inner").removeClass("active");
widget.find(".hotel_selector_filter .destiny_filter[data-destiny=hotel_selector_inner]").addClass("selected");
widget.find(".hotel_selector_inner").addClass("active");
}).blur(function () {
$(this).val("");
setTimeout(function(){
searchHotelElement();
}, 10000);
});
if (hotel_preselection) {
widget.find('.hotel_selector_option#' + hotel_preselection).first().trigger('click');
}
function searchHotelElement(){
var searched_hotel = $("#widget_paraty .hotel_selector_search input").val();
$("#widget_paraty .hotel_selector_inner li").each(function(){
var 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');
}else{
$(this).css('display', 'block');
}
if(searched_hotel == ""){
$(this).css('display', 'block')
}
})
}
}
bookingWidgetController.init();