File: D:/HostingSpaces/EUmans/umansradepo.be/wwwroot/js/main.js
/**
* Created by Pascal on 30/09/15.
*/
$(function () {
resizer();
if (typeof $.throttle === "undefined") rebindThrottleDebounce();
setTimeout(function () {
animations();
}, 800);
$(window).resize(
$.throttle(250, resizer)
);
$(window).scroll(function () {
scroller();
});
jQuery.each(jQuery('textarea[data-autoresize]'), function () { //autosize TextArea
var offset = this.offsetHeight - this.clientHeight;
var resizeTextarea = function (el) {
jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset);
};
jQuery(this).on('keyup input', function () {
resizeTextarea(this);
}).removeAttr('data-autoresize');
});
//get internal link and animate them examp: <a href='#top'>Home</a>
$('a.internalLink').click(function () {
animateScroll($(this));
return false;
});
$('.footerForm .submit').click(function () {
//if($('footer #footerForm input[name="email"]').val()!='') $('footer #footerForm').submit();
$(this).closest('form').submit();
//$('footer .footerForm').submit();
});
$('#quick-form').append('<input type="hidden" name="secretCode" value="isHuman" />');
$('#quick-form .submit-button').click(function () {
var formFields = setQuickFormFields();
var send = validateQuickFields(formFields);
if(send) sendQuickForm(formFields);
});
$("#quick-form #name").change(function () {
$("#quick-form .hidden-inputs").removeClass('non-active');
});
});
function resizer() {
if ($('.home-header .content-container')) {
$('.home-header .content-container').height($('.home-header').width() / 3);
$('.home-header .content-container .button-row').css('bottom', ($('.home-header .content-container').height() / 10));
}
stickyScrollContent();
}
function scroller() {
if ($('.subMenu').hasClass('sticky')) {
if ($(window).scrollTop() <= 160) {
$('.subMenu').removeClass('sticky');
$('.subMenu-placeholder').removeClass('show');
$('.information-page-content .image-container span').css('transform', 'translate3d(0,0, 0)');
}
}
var offsetMenu = $('.subMenu').offset().top - $(window).scrollTop();
if (offsetMenu <= 60) {
$('.subMenu').addClass('sticky');
$('.subMenu-placeholder').addClass('show');
$('.information-page-content .image-container span').css('transform', 'translate3d(0,' + ( ($(window).scrollTop() - 180) * 0.3) + 'px, 0)');
}
if ($('.home-intro-content .image-container')) {
$('.home-intro-content .image-container img').css('top', (((($(window).scrollTop() / 2) * -1) + 60) + 'px'));
}
stickyScrollContent();
}
function convertToRange(value, srcRange, dstRange) {
// value is outside source range return
if (value < srcRange[0] || value > srcRange[1]) {
return NaN;
}
var srcMax = srcRange[1] - srcRange[0],
dstMax = dstRange[1] - dstRange[0],
adjValue = value - srcRange[0];
return (adjValue * dstMax / srcMax) + dstRange[0];
}
function animations() {
$('.animation').each(function () {
if (isElementFullInViewport($(this))) $(this).removeClass('animation');
});
$('.animation-part').each(function () {
if (isElementPartExtraInViewport($(this), 60)) $(this).removeClass('animation-part');
});
}
function isElementFullInViewport(el) {
//special bonus for those using jQuery
if (el.length > 0) {
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.bottom <= (window.innerHeight || $(window).height())
);
}
}
function isElementPartInViewport(el) {
if (el.length > 0) {
//special bonus for those using jQuery
if (typeof jQuery !== 'undefined' && el instanceof jQuery) el = el[0];
var rect = el.getBoundingClientRect();
// DOMRect { x: 8, y: 8, width: 100, height: 100, top: 8, right: 108, bottom: 108, left: 8 }
var windowHeight = (window.innerHeight || document.documentElement.clientHeight);
var windowWidth = (window.innerWidth || document.documentElement.clientWidth);
var vertInView = (rect.top <= windowHeight) && ((rect.top + rect.height) >= 0);
var horInView = (rect.left <= windowWidth) && ((rect.left + rect.width) >= 0);
return (vertInView && horInView);
}
}
function isElementPartExtraInViewport(el, margin) {
if (el.length > 0) {
//special bonus for those using jQuery
if (typeof jQuery !== 'undefined' && el instanceof jQuery) el = el[0];
var rect = el.getBoundingClientRect();
// DOMRect { x: 8, y: 8, width: 100, height: 100, top: 8, right: 108, bottom: 108, left: 8 }
var windowHeight = (window.innerHeight || document.documentElement.clientHeight);
var windowWidth = (window.innerWidth || document.documentElement.clientWidth);
var vertInView = (rect.top <= (windowHeight - margin)) && ((rect.top + rect.height) >= 0);
var horInView = (rect.left <= windowWidth) && ((rect.left + rect.width) >= 0);
return (vertInView && horInView);
}
}
function tabletOrMobile() {
if (window.navigator.userAgent.match(/Mobile/i)
|| window.navigator.userAgent.match(/iPhone/i)
|| window.navigator.userAgent.match(/iPod/i)
|| window.navigator.userAgent.match(/IEMobile/i)
|| window.navigator.userAgent.match(/Windows Phone/i)
|| window.navigator.userAgent.match(/Android/i)
|| window.navigator.userAgent.match(/BlackBerry/i)
|| window.navigator.userAgent.match(/webOS/i)) {
return true;
//alert('True - Mobile - ' + navigator.userAgent);
} else {
//alert('False - Mobile - ' + navigator.userAgent);
//return false;
}
if (window.navigator.userAgent.match(/Tablet/i)
|| window.navigator.userAgent.match(/iPad/i)
|| window.navigator.userAgent.match(/Nexus 7/i)
|| window.navigator.userAgent.match(/Nexus 10/i)
|| window.navigator.userAgent.match(/KFAPWI/i)) {
return true;
//alert('True - Tablet - ' + navigator.userAgent);
}
if ($('body').width() <= 500) {
return true;
}
else {
//alert('False - Tablet - ' + navigator.userAgent);
//return false;
}
}
function stickyScrollContent() {
if ($('.project-detail .information').length && $(window).width() > 625) {
if (!$('.project-detail .information').hasClass('no-sticky-allowed')) {
var offsetDetails = $('.project-detail .information').offset().top - $(window).scrollTop()
if (offsetDetails <= 110) {
$('.project-detail .information').addClass('sticky');
$('.project-detail .information').width(($('.project-detail .content-container .project-images').width() / 6 * 5));
if ($(window).width() > 1464) {
$('.project-detail .information').css('right', $('.project-detail .content-container').offset().left);
}
if ($(window).width() <= 1200) {
$('.project-detail .information').width(($('.project-detail .content-container').width() / 100 * 55));
}
}
if ($('.project-detail .information').hasClass('sticky') && $('.project-detail .information').hasClass('sticky-done') && offsetDetails >= 110) {
$('.project-detail .information').removeClass('sticky-done');
}
if ($('.project-detail .information').hasClass('sticky')) {
if ($(window).scrollTop() <= 220) {
$('.project-detail .information').removeClass('sticky');
$('.project-detail .information').css('width', '');
$('.project-detail .information').css('right', '');
}
if (($(window).scrollTop() + $('.project-detail .information').height() + 175 - $('.magnet-box').offset().top) > 0) {
$('.project-detail .information').addClass('sticky-done');
}
}
}
}
}
function animateScroll(e, offset, time) {
offset = typeof offset !== 'undefined' ? offset : 60;
time = typeof time !== 'undefined' ? time : 800;
var scrollTo = e.prop('href');
scrollTo = scrollTo.substr(scrollTo.indexOf('#') + 1);
if (scrollTo == 'compareTable') offset = 120;
var body = $('html,body');
body.animate({
scrollTop: $('#' + scrollTo).offset().top - offset
}, time);
body.on("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove", function () {
body.stop();
});
}
function validateQuickFields(values) {
//By default the send value is true
var send = true;
//Remove the alert class from the input fields before we validate
$('#quick-form input').removeClass('alert');
//The fields we are going to validate
var fields = ['name', 'email'];
//Loop trough the fields
$.each(fields, function (index, key) {
//Check the element based on the key is not empty, if true, try next element
if (values[key] != '') return;
//If empty
//Set send to false
send = false;
//Add an alert class to the form element of the key
$('#quick-form #' + key).addClass('alert');
//console.log(key);
});
//Return the send variable
return send
}
function setQuickFormFields() {
return {
name: $('#quick-form #name').val(),
email: $('#quick-form #email').val(),
phone: $('#quick-form #phone').val(),
formMessage: $('#quick-form #formMessage').val(),
secretCode: 'isHuman'
};
}
function sendQuickForm(formFields) {
$.ajax({
//Set method to post
method: "POST",
//Add the formFields
data: formFields,
//Get the url from the action url
url: $('#quick-form').attr('action')
}).done(function (msg) {
//What to do when the form is submitted
//If the return message is not the string "true"
if (msg != 'true') {
// Loop trough the message
for (var key in msg) {
//Set the first message for every key
//$('#quick-form .form-element.' + key + ' .error').html(msg[key][0]).addClass('active');
}
//console.log(msg);
//Exit the function
return
}
$('.offer-block .thank-you').addClass('active');
$('.offer-block .form-area').remove();
});
}