Promocode autofill
by mtenschert
HTML
<div class="promocode-item">
Promo (<small></small>) <i class="fa fa-check-circle"></i>
</div>
CSS
@media only screen and (min-width: 500px) {
.promocode-item {
display: none;
position: fixed;
top: 20px;
font-size: 25px;
text-align: center;
padding: 10px;
background-color: rgb(0, 0, 0);
color: white;
z-index: 1000;
width: 30%;
margin-left: 35%;
margin-right: 35%;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
opacity: 0.8;
}
}
@media only screen and (max-width: 499px) {
.promocode-item {
display: none;
position: fixed;
top: 20px;
font-size: 15px;
text-align: center;
padding: 10px;
background-color: rgb(0, 0, 0);
color: white;
z-index: 1000;
width: 100%;
opacity: 0.8;
}
}
.promocode-item small {
font-style: italic;
vertical-align: text-top;
}
.promocode-item i {
color: rgb(6, 161, 6);
}
.invisible-tooltip {
display : none !important;
}
JavaScript
// timeout for optimize360 asynchronous loading
setTimeout(function() {
// get javaScript object "promo" url-parameter ?promo=xxxx
let params = new URLSearchParams(document.location.search);
let promo = params.get("promo");
// function run only(!) if "promo" !== 0
if (promo !== null) {
// function run only(!) if promocode-field is empty
if ($('#booking_parameters_promotionCode').val() == '') {
// autofill in promocode field and add classes
$("#booking_parameters_promotionCode").val(promo);
$("#booking_parameters_promotionCode").addClass("label-shrink");
$("#booking_parameters_promotionCode").addClass("valid-input");
$("#booking_parameters_promotionCode").addClass("ng-pristine");
// addClass for display:none cursor-tooltip
$(".cursor-tooltip").addClass("invisible-tooltip");
// trigger for input
$('#booking_parameters_promotionCode').trigger("input");
// add promocode in autofill info
$('.promocode-item small').text(promo);
// fadeIn function for autofill info
setTimeout(function() {
if ($('#booking_parameters_promotionCode').val() !== '') {
$('.promocode-item').fadeIn(400);
setTimeout(function() {
$('.promocode-item').fadeOut(800);
}, 3000);
}
}, 300)
}
}
}, 1500);