Team:TUDelft/javascript/haupt

// include external html files such as navbar and footer window.include = function(Selector) {

 var sourcePage = $(Selector).attr('data-source');
 $(Selector).load(sourcePage, function() {
   MenuToggleClick();
   MenuToggleHover();
 });

};

// Navigation bar functionality

// On large screens: use hover as dropdown trigger function MenuToggleHover() {

 $('#navbar_parent').on('mouseenter mouseleave', '.hover', function() {
   $(this).toggleClass('dropdownContentOpen');
 })

};

// On small screens: use click as dropdown trigger function MenuToggleClick() {

 $('#navbar_parent').on('click', '.click', function() {
   if ($(this).hasClass('dropdownContentOpen')) {
     $(this).toggleClass('dropdownContentOpen');
   } else {
     closeAllDropdown();
     $(this).toggleClass('dropdownContentOpen');
   }
 })

};

function closeAllDropdown() {

 $('.dropdownContentOpen').toggleClass('dropdownContentOpen');

};

// Small screens: open and close side menu, with animation // Both triggered in html <onclick='function()'> function openSideMenu() {

 $('#sideBar')
   .css('right', '-300px')
   .css('display', 'block')
   .animate({
     right: '0'
   });
 $('#openSideMenu').hide();
 $('#closeSideMenu').css('display', 'block');
 $('.hasdropdown').removeClass('hover').addClass('click');

};

function closeSideMenu() {

 $('#sideBar')
   .animate({
     right: '-300px'
   });
 $('#openSideMenu').show();
 $('#closeSideMenu').css('display', 'none');
 $('.hasdropdown').removeClass('click').addClass('hover');
 closeAllDropdown();

};