Created
December 7, 2017 16:37
-
-
Save mustardBees/81b8ed011e56e3d6feecc4dbcaff3967 to your computer and use it in GitHub Desktop.
Mews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mews.Distributor({ | |
configurationIds: $.map(iweb_mews_config, function (o) { | |
return o["configurationid"]; | |
}), | |
hotelIds : ['1', '2'], // Hacky workaround to force Distributor into chain mode. | |
}, function (distributor) { | |
// Hook into booking links, optionally prepopulate a voucher code. | |
$('.js-booking-link').on('click', function (e) { | |
e.preventDefault(); | |
if ($(e.target).attr('data-voucher')) { | |
distributor.setVoucherCode($(e.target).data('voucher')); | |
} | |
distributor.open(); | |
}); | |
// Hook into booking forms. Prepopulate date and hostel. | |
$('.clink-booknow form').on('submit', function (e) { | |
e.preventDefault(); | |
$('#hostel option:selected', e.target).data('cityid') | |
var start_date = new Date($('#dci', e.target).val()); | |
var nights = parseInt($('#nights', e.target).val()); | |
var end_date = get_end_date(start_date, nights); | |
distributor.setStartDate(start_date); | |
distributor.setEndDate(end_date); | |
console.log(iweb_mews_config[$('#hostel', e.target).val()]["cityid"]); | |
distributor.setCity(iweb_mews_config[$('#hostel', e.target).val()]["cityid"]); | |
distributor.showRooms(iweb_mews_config[$('#hostel', e.target).val()]["hotelid"]); | |
distributor.open(); | |
}); | |
}); | |
// Work out end date based on start date and number of nights. | |
function get_end_date(start_date, nights) { | |
var end_date = new Date(start_date); | |
end_date.setDate(end_date.getDate() + nights); | |
return end_date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment