"use strict"; function validateEmail(email) { var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{1,4})?$/; if (!emailReg.test(email)) { return false; } else { return true; } } function validateContactNumber(number) { var numberReg = /^((\+)?[1-9]{1,3})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/; if (!numberReg.test(number)) { return false; } else { return true; } } function validateTextOnly(text) { var textReg = /^[A-z]+$/; if (!textReg.test(text)) { return false; } else { return true; } } function validateNumberOnly(number) { var numberReg = /^[0-9]+$/; if (!numberReg.test(number)) { return false; } else { return true; } } function checkElementValidation(child, type, check, error) { child.parent().find('.alert').remove(); if ( child.val() == "" && child.attr("data-required") == "required" ) { child.removeClass("success"); child.addClass("error"); child.parent().append('
' + child.parents("form").attr("data-required") + '
'); child.parent().find('.error-message').css("margin-left", -child.parent().find('.error-message').innerWidth()/2); return false; } else if( child.attr("data-validation") == type && child.val() != "" ) { if( !check ) { child.removeClass("success"); child.addClass("error"); child.parent().append('
' + error + '
'); child.parent().find('.error-message').css("margin-left", -child.parent().find('.error-message').innerWidth()/2); return false; } } child.removeClass("error"); child.addClass("success"); return true; } function checkFormValidation(el) { var valid = true, children = el.find('input[type="text"], textarea'); children.each(function(index) { var child = children.eq(index); var parent = child.parents("form"); if( !checkElementValidation(child, "email", validateEmail(child.val()), parent.attr("data-email")) || !checkElementValidation(child, "phone", validateContactNumber(child.val()), parent.attr("data-phone")) || !checkElementValidation(child, "text_only", validateTextOnly(child.val()), parent.attr("data-text")) || !checkElementValidation(child, "number", validateNumberOnly(child.val()), parent.attr("data-number")) ) { valid = false; } }); return valid; } jQuery.fn.isOnScreen = function(){ var win = jQuery(window); var viewport = { top : win.scrollTop(), left : win.scrollLeft() }; viewport.right = viewport.left + win.width(); viewport.bottom = viewport.top + win.height(); var bounds = this.offset(); bounds.right = bounds.left + this.outerWidth(); bounds.bottom = bounds.top + this.outerHeight(); return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); }; jQuery.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); jQuery.each(a, function() { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; }; jQuery(function($) { /* Top bar */ function topBarSize() { var el = $('.top-bar .container'); el.css( { 'display' : 'none', 'height' : 'auto' }).attr('data-height', el.height()).attr('style', 'height: 0;').parent().removeClass('open'); } $('.top-bar .close').on('click', function() { var el = $('.top-bar'); var child = $('.top-bar .container'); el.toggleClass('open'); if( el.hasClass('open') ) { child.height(child .attr('data-height')); } else { child.attr('style', 'height: 0;'); } }); topBarSize(); $(window).resize(function() { topBarSize(); siteNavigationSizing(); }); /* Megamenu */ $('.megamenu > .sub-menu').addClass('container').removeClass('sub-menu').wrap('