File "main-theme.js"

Full Path: /srv/www/www.cadoro.it/src/js/main-theme.js
File size: 3.31 KB
MIME-type: text/plain
Charset: utf-8

$(function () {
  $(window).on('scroll', function () {
    // header
    var header_top = $('header').data('top');
    if (header_top === undefined) {
      header_top = $('header').offset().top;
      $('header').data('top', header_top);
    }
    var scroll_top = $(window).scrollTop();
    var $body = $('body');
    if (scroll_top > header_top) {
      if (!$body.hasClass('header-sticky')) {
        $('body').addClass('header-sticky')
        $('.hero').css('overflow', 'hidden')
      }
    } else if (scroll_top <= header_top) {
      if ($body.hasClass('header-sticky')) {
        $('body').removeClass('header-sticky')
        $('.hero').css('overflow', 'initial')
      }
    }
    // infinite scroll
    var $loader = $('.scroll-loader');
    if ($loader.length) {
      var loader_top = $loader.offset().top;
      if ((loader_top + 80 - $(window).height())  < scroll_top) {
        var $img = $loader.find('img');
        if (!$img.is(':visible')) {
          $loader.find('strong').hide();
          $img.show();
          setTimeout(function () {
            $.ajax({
              url: $loader.data('batch'),
              success: function (data, textStatus, jqXHR) {
                $loader.replaceWith(data);
              }
            });
          }, 250);
        }
      }
    }
  });
  $('body').on('click', '.click-loader', function (e) {
    e.preventDefault();
    var $loader = $('.click-loader');
    var $img = $loader.find('img');
    if (!$img.is(':visible')) {
      $loader.find('strong').hide();
      $img.show();
      setTimeout(function () {
        $.ajax({
          url: $loader.data('batch'),
          success: function (data, textStatus, jqXHR) {
            $loader.replaceWith(data);
          }
        });
      }, 250);
    }
  });
  if (self.location.hash) {
    var $target = $('a[name="' + self.location.hash + '"]');
    if ($target.length) {
      var scrollTop = $target.offset().top
      setTimeout(function () {
        $('html, body').stop().animate({
          scrollTop: scrollTop - 100
        }, 1000, 'easeInOutExpo');
      }, 500);
    }
  }
  $('a[data-behaviour=profile-toolbar-toggle]').click(function (e) {
    e.preventDefault();
    if ($('.profile-toolbar-links').is(':visible')) {
      $('.profile-toolbar').removeClass('open');
      $('.profile-toolbar-links').slideUp()
    } else {
      $('.profile-toolbar').addClass('open');
      $('.profile-toolbar-links').slideDown()
    }
  });
  $('.header .dropdown-toggle').hover(function() {
    if (!$(this).closest('li').hasClass('open')) {
      $(this).trigger('click');
    }
  },
  function() {
    setTimeout(function() {
      if(!$('.header .dropdown-menu').is(":hover")){
        if($(".header .dropdown-toggle").closest("li").hasClass("open")){
          $("body").trigger("click");
        }
      }
    }, 200);
  }).click(function (e) {
    if ($(this).closest('li').hasClass('open')) {
      self.location.href = $(this).attr('href');
    }
  });
  $(".header .dropdown-menu").hover(
    function(){

    },
    function(){
      if($(".header .dropdown-toggle").closest("li").hasClass("open")){
        $("body").trigger("click");
      }
    }
  );
  if ($(document).width() < 768) {
    $('.hero').before($('.header'))
  }
  $('input[type=text], input[type=email], input[type=password], input[type=password]').attr('autocomplete', 'off');
});