$.fn.isInViewport = function() { var elementTop = $(this).offset().top; var elementBottom = elementTop + $(this).outerHeight(); var viewportTop = $(window).scrollTop(); var viewportBottom = viewportTop + $(window).height(); return elementBottom > viewportTop && elementTop < viewportBottom; }; var lang = $('html').attr("lang"); $(document).ready(function() { $("input[type='date']").click(function(){ $(this).addClass("no-before"); }); // Direct browser to top right away if (window.location.hash) { scroll(0,0); // Takes care of some browsers issue setTimeout(function(){ scroll(0,0); },1); // Smooth scroll to the anchor id $('html, body').stop().animate({ scrollTop: $(window.location.hash).offset().top - $("nav").height() }, 1000,'swing'); } // Current click function $('a[href*="#"]').on('click', function(){ var target = this.hash; $target = $(target); $('html, body').stop().animate({ 'scrollTop': +$target.offset().top - $("nav").height() }, 900, 'swing'); }); $('#burger').on('click', function() { $('#menu-mobile').fadeIn(); }); $('#close-menu').on('click', function() { $('#menu-mobile').fadeOut(); }); $('.main-carousel').each(function() { var owl = $(this); owl.owlCarousel({ nav: false, animateIn: 'fadeIn', animateOut: 'fadeOut', autoplay: false, autoplayTimeout: 5000, items: 1, dots: false, loop: true }); $('.custom-prev-btn').click(function() { owl.trigger('prev.owl.carousel'); }); $('.custom-next-btn').click(function() { owl.trigger('next.owl.carousel'); }); // Show first slide var slides_content_wrapper = owl.parent().find('.owl-carousel-slides-content'); if (slides_content_wrapper.length > 0) { slides_content_wrapper.find('.content').hide(); slides_content_wrapper.find('.content:first').fadeIn(); owl.on('next.owl.carousel', function(e) { // var index = getOwlCarouselIndex(e); var dataId = owl.find('.owl-item.active .slide').attr("data-id"); slides_content_wrapper.find('.content').hide(); slides_content_wrapper.find('.content[data-id='+ dataId +']').fadeIn('slow'); }); owl.on('prev.owl.carousel', function(e) { var dataId = owl.find('.owl-item.active .slide').attr("data-id"); slides_content_wrapper.find('.content').hide(); slides_content_wrapper.find('.content[data-id='+ dataId +']').fadeIn('slow'); }); } }); $('.products-mobile, .portfolio-carousel').each(function() { var owl = $(this); owl.owlCarousel({ nav: false, items: 1, dots: true, autoplay: true, autoplayTimeout: 5000, }); }); $('.events-carousel').each(function() { var owl = $(this); owl.owlCarousel({ nav: false, items: 1, autoplay: true, autoplayTimeout: 5000, dots: true, responsive:{ 992: { items: 2 } } }); }); $('.partners-carousel').each(function() { var owl = $(this); owl.owlCarousel({ nav: false, items: 2, autoplay: true, autoplayTimeout: 5000, dots: true, responsive:{ 992: { items: 4 } } }); }); $('.bord-directors-carousel').each(function() { var owl = $(this); owl.owlCarousel({ nav: false, items: 1, autoplay: true, autoplayTimeout: 5000, dots: true, responsive:{ 992: { items: 4 } } }); }); $('.otherNews-carousel').each(function() { var owl = $(this); owl.owlCarousel({ nav: false, items: 1, dots: true, autoplay: true, autoplayTimeout: 5000, }); }); initProductsCarousel(); $('#operations-page .image-preview').on('click', function() { var img_index = $(this).closest('.image-preview-wrapper').index() + 1; $('#gallery .images-wrapper img:nth-child(' + img_index + ')').show(); $('#gallery').fadeIn(); }); $('#gallery').on('click', function() { $(this).fadeOut(); }); $('#gallery img').on('click', function(e) { e.stopPropagation(); }); $('#gallery .custom-next-btn').on('click', function(e) { e.stopPropagation(); var btn = $(this); var gallery = btn.closest('#gallery'); var image_visible = gallery.find('.images-wrapper img:visible'); image_visible.fadeOut(); if (image_visible.next('img').length == 0) { gallery.find('.images-wrapper img:first').fadeIn(); } else { image_visible.next('img').fadeIn(); } }); $('#gallery .custom-prev-btn').on('click', function(e) { e.stopPropagation(); var btn = $(this); var gallery = btn.closest('#gallery'); var image_visible = gallery.find('.images-wrapper img:visible'); image_visible.fadeOut(); if (image_visible.prev('img').length == 0) { gallery.find('.images-wrapper img:last').fadeIn(); } else { image_visible.prev('img').fadeIn(); } }); $('select[name="applicant_type"]').on('change', function() { var type = $(this).val(); $('.form-group.employee, .form-group.owner').hide(); if (type == "employee") { $('.form-group.employee').show(); } else { $('.form-group.owner').show(); } }); $(".btn-description").click(function(){ $(this).closest("li").find(".description").slideToggle(); }); $("#careers-page .btn-apply-now").click(function(){ var positionId = $(this).closest("li").attr("data-position"); $(".application-form [name='position']").val(positionId).trigger("change"); $(".application-form").fadeIn(); $('html, body').animate({ scrollTop: $("#careers-page .application-form").offset().top - $("nav").height() }, 1000 ); }); $(".fileUpload #uploadBtn").change(function(){ var value = $(this).val(); value = value.replace("C:\\fakepath\\", ""); $(this).closest(".fileUpload").find("#uploadFile").text(value); }); $(".contactForm, .complaintsForm, .productssForm").submit(function(e){ e.preventDefault(e); var form = $(this); var htmlResponse = ''; $.ajax({ type : "post", url : form.attr("action"), data : form.serialize(), beforeSend: function(data) { if(lang == "en"){ form.find("button[type='submit']").text("Sending..."); } else { form.find("button[type='submit']").text("قيد الإرسال"); } form.find(".form-control").prop("disabled", true); }, error: function(data){ if (data.status == 422) { $.each(data.responseJSON.errors, function(key, val){ htmlResponse += '