"use strict";
// svg icons support ie11
(function () {
svg4everybody();
})(); // carousel arrows
var navArrows = ["\n ", ""]; // owl carousel
$(document).ready(function () {
var sliderReview = $('.js-slider-review');
sliderReview.owlCarousel({
items: 3,
nav: true,
navElement: 'button',
navText: navArrows,
dots: false,
loop: true,
smartSpeed: 700,
responsive: {
0: {
items: 1,
autoHeight: true
},
768: {
items: 3
}
}
});
var sliderComment = $('.js-slider-comment');
sliderComment.owlCarousel({
items: 3,
nav: true,
navElement: 'button',
navText: navArrows,
dots: false,
loop: true,
smartSpeed: 700,
responsive: {
0: {
items: 1,
autoHeight: true
},
768: {
items: 2
},
1024: {
items: 3
}
}
});
}); // toggle body theme
(function () {
var switchTheme = $('.js-switch-theme'),
body = $('body');
switchTheme.on('change', function () {
if (!body.hasClass('dark')) {
body.addClass('dark');
localStorage.setItem('darkMode', "on");
} else {
body.removeClass('dark');
localStorage.setItem('darkMode', "off");
}
});
})(); // faq
(function () {
var item = $('.faq__item, .questions__item'),
head = $('.faq__head, .questions__head'),
body = $('.faq__body, .questions__body');
head.on('click', function () {
var thisHead = $(this);
thisHead.parents('.faq__item, .questions__item').toggleClass('active');
thisHead.parents('.faq__item, .questions__item').find('.faq__body, .questions__body').slideToggle();
});
})();
(function () {
var item = $('.faq_button');
item.on('click', function () {
window.location.href = 'faq';
});
})();
(function () {
var item = $('.popup__select');
item.on('change', function () {
var value = $(this).val();
if (value === "") {
$(this).addClass('popup__select_has_no_value');
} else {
$(this).removeClass('popup__select_has_no_value');
}
});
})(); // magnificPopup
(function () {
var link = $('.js-popup-open');
link.magnificPopup({
type: 'inline',
fixedContentPos: true,
removalDelay: 200,
callbacks: {
beforeOpen: function beforeOpen() {
this.st.mainClass = this.st.el.attr('data-effect');
}
}
});
})(); // header
(function () {
var header = $('.header'),
wrapper = header.find('.header__wrapper'),
burger = header.find('.header__burger');
burger.on('click', function () {
burger.toggleClass('active');
wrapper.toggleClass('visible');
$('html').toggleClass('no-scroll');
$('body').toggleClass('no-scroll');
});
})(); // pricing options
(function () {
var view = $('.pricing__view');
view.on('click', function (e) {
e.preventDefault();
$(this).toggleClass('active');
$(this).parents('.pricing__item').find('.pricing__options').slideToggle();
});
})(); // privacy options
(function () {
var view = $('.privacy__view');
view.on('click', function (e) {
e.preventDefault();
$(this).toggleClass('active');
$(this).parents('.privacy__item').find('.privacy__options').slideToggle();
});
})(); // mail API
function GetMail() {
// // const fillData = {
// // firstname: $('#first-name').value,
// // lastname: $('#last-name').value,
// // useremail: $('#user-email').value
// // }
// // const rawResponse = await fetch('http://localhost:1337/email', {
// // method: 'POST',
// // headers: {
// // 'Accept': 'application/json',
// // 'Content-Type': 'application/json'
// // },
// // body: JSON.parse(fillData)
// // });
// // rawResponse.then((res) => console.log(res))
// // .catch((err) => console.log(err))
// const content = await rawResponse;
console.log("todo: submit info to mailchimp api");
}
var mcBtn = $('#submitMailChimpButton');
mcBtn.on('click', function () {
var mcForm = $('form[name="mc-embedded-subscribe-form"]');
if (validateMailChimpForm()) {
mcForm.submit();
}
});
function validateMailChimpForm() {
validateField('mce-FNAME', 'popup__form_field_error');
validateField('mce-LNAME', 'popup__form_field_error');
validateField('mce-ENTITYTYPE', 'popup__form_field_error');
validateField('mce-TEAMSIZE', 'popup__form_field_error');
validateField('mce-ACCOUNTING', 'popup__form_field_error');
validateEmailField('mce-EMAIL', 'popup__form_field_error');
var invalidFields = $('.popup__form_field_error');
return invalidFields.length == 0;
}
function validateEmailField(fieldName, errorClass) {
var fieldQuery = '#' + fieldName;
var field = $(fieldQuery);
if (field.length == 0) {
return false;
}
var fieldValue = field.val();
var validRegex = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/;
if (fieldValue && fieldValue.match(validRegex)) return true;
field.addClass(errorClass);
return false;
}
function validateField(fieldName, errorClass) {
var fieldQuery = '#' + fieldName;
var field = $(fieldQuery);
if (field.length == 0) {
console.log("Field " + fieldName + " not found! ");
return false;
}
var fieldValue = field.val();
if (fieldValue && fieldValue.trim().length > 0) return true;
field.addClass(errorClass);
return false;
}
function getFieldValue(fieldName) {
var fieldQuery = '#' + fieldName;
var field = $(fieldQuery);
var fieldValue = field.val();
return fieldValue;
}
function formFieldChanged(fieldName) {
var fieldQuery = '#' + fieldName;
var field = $(fieldQuery);
var fieldValue = field.val();
if (fieldValue && fieldValue.trim().length > 0) {
field.removeClass('popup__form_field_error');
field.removeClass('contact__form_field_error');
}
}
var contactBtn = $('#submitContactUsButton');
contactBtn.on('click', function () {
if (validateContactUsForm()) {
var msgPayload = getContactMessagePayload();
$.ajax(msgPayload).done(function (response) {
$('#contact-us-form')[0].reset();
console.log(response);
window.location.href = "https://looch.money/contact-confirm";
});
} else {
console.log("Form is not valid");
}
});
function getContactMessagePayload() {
var senderEmail = getFieldValue('contact-SenderEmail');
var lastName = getFieldValue('contact-LastName');
var firstName = getFieldValue('contact-FirstName');
var msg = getFieldValue('contact-Message');
var subject = "Contact form inquiry from " + firstName + " " + lastName;
var replyToAddress = senderEmail;
var payload = {
"url": "https://eg6awnoma4.execute-api.us-west-2.amazonaws.com/development/sendMail",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify({
"toEmailAddresses": ["support@looch.money"],
"sourceEmail": "support@looch.money",
"bodyData": msg,
"subjectdata": subject,
"firstName": firstName,
"lastName": lastName,
"replyToAddresses": [replyToAddress]
})
};
return payload;
}
function validateContactUsForm() {
validateField('contact-FirstName', 'contact__form_field_error');
validateField('contact-LastName', 'contact__form_field_error');
validateField('contact-Message', 'contact__form_field_error');
validateEmailField('contact-SenderEmail', 'contact__form_field_error');
var invalidFields = $('.contact__form_field_error');
return invalidFields.length == 0;
} // aos animation
AOS.init();