/*--------------------------------------------------
Project:       ismoderna
-----------------------------------------------------

    JS INDEX
    ================================================
   
    * One Page Scroll
    * slick Menu js 
    * slick Nav
 
    * bottom to top
    ================================================*/

(function ($) {
  "use strict";
  var $main_window = $(window);

  /*====================================
                One Page Scroll
    ======================================*/

  // Select all »a« elements with a parent class »links« and add a function that is executed on click
  $('.navbar-nav .nav-item a').on('click', function (e) {
    // Define variable of the clicked »a« element (»this«) and get its href value.
    var href = $(this).attr('href');
    // Run a scroll animation to the position of the element which has the same id like the href value.
    $('html, body').animate({
      scrollTop: $(href).offset().top
    }, '300');
    // Prevent the browser from showing the attribute name of the clicked link in the address bar
    e.preventDefault();
  });


  /*====================================
      slick nav
  ======================================*/
  var logo_path = jQuery('.mobile-menu').data('logo');
  var logo_link = jQuery('.mobile-menu').data('link');
  var logo_type = jQuery('.mobile-menu').data('type');
  let logo;

    if (logo_type === 'text') {
      logo = '<a href="' + logo_link + '"></a>';
    }else {
      logo = '<a href="' + logo_link + '"><img src="' + logo_path + '" class="img-fluid" alt="logo"></a>';;
    }

  jQuery('.navbar-nav').slicknav({
    appendTo: '.mobile-menu',
    removeClasses: true,
    label: '',
    closedSymbol: '<i class="fa fa-angle-right"><i/>',
    openedSymbol: '<i class="fa fa-angle-down"><i/>',
    brand: logo
  });


  function ismoderna_toggle_icon_burger() {

        const list = document.querySelectorAll(".slicknav_nav li a");

            // get first element to be focused inside modal
            const firstFocusableElement = document.getElementById('slicknav_btnn');

            const logo = document.querySelector('.nav-brand a');

            const firstFocusableElementclass = document.querySelector('.slicknav_collapsed');

            // get last element to be focused inside modal
            const last = list[list.length - 1];
            const lastFocusableElement = last;

            document.addEventListener('keydown', function (e) {
                let isTabPressed = e.key === 'Tab' || e.keyCode === 9;

                if (!isTabPressed) {
                    return;
                }

                if(event.shiftKey && event.keyCode == 9 && document.activeElement === firstFocusableElement) { 
              
                    lastFocusableElement.focus();
                    e.preventDefault();
                }
                if(event.shiftKey && event.keyCode == 9 && document.activeElement === firstFocusableElementclass) { 
              
                  logo.focus();
                    e.preventDefault();
                }

                // if shift key pressed for shift + tab combination
                if (e.shiftKey) {
                    if (document.activeElement === firstFocusableElement) {
                        lastFocusableElement.focus();
                        e.preventDefault();
                    }
                } else {
                    if (document.activeElement === lastFocusableElement) {
                        firstFocusableElement.focus();
                        e.preventDefault();
                    }
                }
            });
    }


    ismoderna_toggle_icon_burger();

  /*------------ Wow-js -------------*/
  new WOW().init();

  /*====================================
            bottom to top
  ======================================*/

  var btn = $('#btn-to-top');
  $(window).on('scroll', function () {
    if ($(window).scrollTop() > 300) {
      btn.addClass('show');
    } else {
      btn.removeClass('show');
    }
  });
  btn.on('click', function (e) {
    e.preventDefault();
    $('html, body').animate({
      scrollTop: 0
    }, '300');
  });

document.addEventListener("touchstart", function(){}, true);

})(jQuery);