fixing the off canvas menu sub menu animation
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 17 Apr 2018 12:09:41 +0000 (08:09 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 17 Apr 2018 12:09:41 +0000 (08:09 -0400)
the off canvas submenus weren't hiding and showing properly

js/app.js
js/custom/pageSetup.js

index a1fec59..ac86051 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -17,355 +17,364 @@ $(document).ready(function () {
 
    // console.log(menu_items)
    oc_menu.children('ul').on("click", '> li', function(event){
-       // console.log(event.target);
-       // console.log($(this));
+     // console.log(event.target);
+     // console.log($(this));
    })
-
+   let collapseMenu;
    menu_items.each(function(){
        let menuThis = $(this);
-      
+  
        menuThis.on("click", function(){
            other_menu = $(this).closest('ul.sub-menu-section').siblings('ul.sub-menu-section').not(".oc-home-link");
        })
        if( $(this).children('ul').length > 0 ){
            let menuParent = $(this).parent();
-  
            $(this).on("click", function(e){
+               console.log($(this).parent())
+               if( $(this).parent().hasClass('sub-menu-section') ){
+                  collapseMenu = true;
+               }
+               else{
+                   collapseMenu = false;
+               }
+               e.stopImmediatePropagation();
+              
                // collapse the nav menu that isn't in focus (primary or secondary)
-               other_menu.toggleClass("oc-hidden");
-
+               if( $('.oc-open').length > 0 ){
+                  childMenuVisible = true;
+               } else {
+                  childMenuVisible = false;
+               }
+            
                // alter the orientation of the nav arrow, it's the only el that uses a plain open class instead of oc-open
                $(this).children('a').toggleClass('open');
-               e.stopImmediatePropagation();
-               // problem is here, this is a blanket toggle which affects sub menus unintentionally
                $(this).children('a').siblings('ul').toggleClass('oc-open');
-
+               console.log(childMenuVisible);
+               if( collapseMenu && childMenuVisible){
+                   other_menu.toggleClass("oc-hidden"); 
+                   // $(this).children('a').siblings('ul').toggleClass('oc-open');         
+               } else if( collapseMenu){
+                   other_menu.toggleClass("oc-hidden");
+               }
                // For animation purposes
                $(this).toggleClass('oc-expanded');
                $(this).siblings().toggleClass("oc-collapsed");
                $('.oc-overlay').animate({ scrollTop: 0 }, "slow");
-           })
-
-           $(this).children('a').on('click', function(e){
-               e.preventDefault();
-           })
-
-       } else {
-           let url = $(this).children('a').attr('href');
-           $(this).on("click", function(){
-               window.location = url;
-           })
-       }
-   });
-
-
-
-
-
-   $('ul.children').each(function () {
-       $(this).before('<a class="toggle" href="#"></a>');
-   });
-   $('#glm-member-password-lost-link').click(function() {
-       $('#glm-member-password-lost-form').show();
-   });
-  
-
-   $('.top-bar-section').find('ul.sub-menu.dropdown').each(function (){
-       var menuImg = $(this).parent('li').prop('id');
-       var menuNum = menuImg.match(/\d+/)[0];
-       var menuImgSrc = 'img_for_menu_' + menuNum;
-       if (window['img_for_menu_' + menuNum]) {
-           $(this).find('li.image-placeholder').html('<img src="' + eval(menuImgSrc) + '">');
-       } else {
-           $(this).find('li.image-placeholder').parent('ul').addClass('no-image-subul');
-           $(this).find('li.image-placeholder').remove();
-       }
-       //console.log('ul = ' + menuImg);
-       //console.log('menu-id = ' + menuNum);
-   });
-
-   $("#searchIcon").click(function(){
-       if($("#topSearchForm").css("display") == "none"){
+         })
+
+         $(this).children('a').on('click', function(e){
+             e.preventDefault();
+         })
+
+     } else {
+         let url = $(this).children('a').attr('href');
+         $(this).on("click", function(){
+             window.location = url;
+         })
+     }
+ });
+
+ $('ul.children').each(function () {
+     $(this).before('<a class="toggle" href="#"></a>');
+ });
+ $('#glm-member-password-lost-link').click(function() {
+     $('#glm-member-password-lost-form').show();
+ });
+
+ $('.top-bar-section').find('ul.sub-menu.dropdown').each(function (){
+     var menuImg = $(this).parent('li').prop('id');
+     var menuNum = menuImg.match(/\d+/)[0];
+     var menuImgSrc = 'img_for_menu_' + menuNum;
+     if (window['img_for_menu_' + menuNum]) {
+         $(this).find('li.image-placeholder').html('<img src="' + eval(menuImgSrc) + '">');
+     } else {
+         $(this).find('li.image-placeholder').parent('ul').addClass('no-image-subul');
+         $(this).find('li.image-placeholder').remove();
+     }
+     //console.log('ul = ' + menuImg);
+     //console.log('menu-id = ' + menuNum);
+ });
+
+ $("#searchIcon").click(function(){
+     if($("#topSearchForm").css("display") == "none"){
 //           $("#searchform").css("display", "inline");
-           $("#topSearchForm").toggle("slide");
-           $("#searchIcon").css("visibility", "hidden");
-       }
-        $("#lar-search").focus();
-   });
-   $("#lar-search").blur(function(){
-       $("#topSearchForm").toggle("slide");
-       $("#searchIcon").css("visibility", "visible");
-   });
-
-
-   // MOBILE SEARCH
-   var right = $('#mobile-search-form').offset().right;
-   $("#mobile-search").on("click", function(){
-       $("#mobile-search-form").css({right:right})  // Set the left to its calculated position
-       .animate({"right":"0px"}, "slow");
-   });
-   $(".mobile-search-close").on("click", function(){
-       $("#mobile-search-form").css({right:right})  // Set the left to its calculated position
-       .animate({"right":"-100%"}, "slow");
-   });
-   var countup_options = {
-       useEasing: true,
-       useGrouping: true,
-       separator: ',',
-       decimal: '.',
-   };
-   $.fn.isInViewport = function(offset) {
-       var elementTop      = $(this).offset().top;
-       var elementBottom   = elementTop + $(this).outerHeight();
-       var viewportTop     = $(window).scrollTop();
-       var viewportBottom  = viewportTop + $(window).height();
-       var center          = (viewportBottom + viewportTop) / 2 + parseInt(offset);
-       return [elementBottom > viewportTop && elementTop < center,$(this)];
-   };
-   var blocks = [$('#block-1'),$('#block-2'),$('#block-3'),$('#block-4')];
-   var posts  = $('.home-feed-post');
-  
-   var blog_position = $("#home-feed-posts").position();
-   var scrolled = 0;
-   var the_number = parseInt($('.first-blur').text());
-
-   var our_impact_seen         = false;
-   $(window).on("scroll", function() {
-       var page_position  = $(window).scrollTop();     
-           if( $(window).width() < 1024 ){
-               $.each(blocks, function(){
-                   if( $(this).length > 0){
-                       var test_scroll = $(this).isInViewport(-75);
-                      
-                       if( test_scroll[0]){
-                           $(this).find(".overlay").addClass('mobile-overlay');
-                           $(this).find(".overlay").css("background-color", "rbga(0,0,0, .7)");
-                       }else{
-                           $(this).find(".overlay").removeClass('mobile-overlay');
-                           $(this).find(".overlay").css("background-color", "rbga(0,0,0, 0)");
-                       }
-                   }
-               });
-               $.each(posts, function(){
+         $("#topSearchForm").toggle("slide");
+         $("#searchIcon").css("visibility", "hidden");
+     }
+      $("#lar-search").focus();
+ });
+ $("#lar-search").blur(function(){
+     $("#topSearchForm").toggle("slide");
+     $("#searchIcon").css("visibility", "visible");
+ });
+
+
+ // MOBILE SEARCH
+ var right = $('#mobile-search-form').offset().right;
+ $("#mobile-search").on("click", function(){
+     $("#mobile-search-form").css({right:right})  // Set the left to its calculated position
+     .animate({"right":"0px"}, "slow");
+ });
+ $(".mobile-search-close").on("click", function(){
+     $("#mobile-search-form").css({right:right})  // Set the left to its calculated position
+     .animate({"right":"-100%"}, "slow");
+ });
+ var countup_options = {
+     useEasing: true,
+     useGrouping: true,
+     separator: ',',
+     decimal: '.',
+ };
+ $.fn.isInViewport = function(offset) {
+     var elementTop      = $(this).offset().top;
+     var elementBottom   = elementTop + $(this).outerHeight();
+     var viewportTop     = $(window).scrollTop();
+     var viewportBottom  = viewportTop + $(window).height();
+     var center          = (viewportBottom + viewportTop) / 2 + parseInt(offset);
+     return [elementBottom > viewportTop && elementTop < center,$(this)];
+ };
+ var blocks = [$('#block-1'),$('#block-2'),$('#block-3'),$('#block-4')];
+ var posts  = $('.home-feed-post');
+  var blog_position = $("#home-feed-posts").position();
+ var scrolled = 0;
+ var the_number = parseInt($('.first-blur').text());
+
+ var our_impact_seen         = false;
+ $(window).on("scroll", function() {
+     var page_position  = $(window).scrollTop();   
+         if( $(window).width() < 1024 ){
+             $.each(blocks, function(){
+                 if( $(this).length > 0){
+                     var test_scroll = $(this).isInViewport(-75);
                   
-                   if( $(this).length > 0){
-                      
-                       var test_scroll = $(this).isInViewport(-75);
-                       console.log( test_scroll[0] );
-                       if( test_scroll[0]){
-                           $(this).find(".overlay").addClass('blog-overlay');
-                           $(this).find(".overlay").css("background-color", "rbga(0,0,0, .7)");
-                       }else{
-                           $(this).find(".overlay").removeClass('blog-overlay');
-                           $(this).find(".overlay").css("background-color", "rbga(0,0,0, 0)");
-                       }
-                   }
-               });
-           }
-           if($("#home-feed-posts").length ){
-               if($("#home-feed-posts").isInViewport(100)[0]){
-                   $('#home-feed-posts').css("opacity", 1);
-                   $('#home-feed-posts').addClass("fadeInUp");
-               }
-           }
-
-       if( $('.blur-action').length > 0 ){
-           if( $(".blur-action").isInViewport(100)[0] && our_impact_seen == false  ){
-               $('.blur-container').children('span:first-child').addClass("in-sight");
-
-               window.setTimeout(function(){
-                   $('.first-blur').animate({opacity: 1}, 200);
-                   var our_impact_counter = new CountUp('first-blur', 0, parseInt(the_number), 0, 2.5, countup_options);
-                   if (!our_impact_counter.error) {
-                   our_impact_counter.start();
-                   } else {
-                   console.error(our_impact_counter.error);
-                   }
-               }, 1000);
+                     if( test_scroll[0]){
+                         $(this).find(".overlay").addClass('mobile-overlay');
+                         $(this).find(".overlay").css("background-color", "rbga(0,0,0, .7)");
+                     }else{
+                         $(this).find(".overlay").removeClass('mobile-overlay');
+                         $(this).find(".overlay").css("background-color", "rbga(0,0,0, 0)");
+                     }
+                 }
+             });
+             $.each(posts, function(){
               
-               window.setTimeout(function(){$('.blur-container').children("span:nth-child(3)").addClass("in-sight");}, 600);
-               our_impact_seen         = true;
-           }
+                 if( $(this).length > 0){
+                  
+                     var test_scroll = $(this).isInViewport(-75);
+                     console.log( test_scroll[0] );
+                     if( test_scroll[0]){
+                         $(this).find(".overlay").addClass('blog-overlay');
+                         $(this).find(".overlay").css("background-color", "rbga(0,0,0, .7)");
+                     }else{
+                         $(this).find(".overlay").removeClass('blog-overlay');
+                         $(this).find(".overlay").css("background-color", "rbga(0,0,0, 0)");
+                     }
+                 }
+             });
+         }
+         if($("#home-feed-posts").length ){
+             if($("#home-feed-posts").isInViewport(100)[0]){
+                 $('#home-feed-posts').css("opacity", 1);
+                 $('#home-feed-posts').addClass("fadeInUp");
+             }
+         }
+
+     if( $('.blur-action').length > 0 ){
+         if( $(".blur-action").isInViewport(100)[0] && our_impact_seen == false  ){
+             $('.blur-container').children('span:first-child').addClass("in-sight");
+
+             window.setTimeout(function(){
+                 $('.first-blur').animate({opacity: 1}, 200);
+                 var our_impact_counter = new CountUp('first-blur', 0, parseInt(the_number), 0, 2.5, countup_options);
+                 if (!our_impact_counter.error) {
+                 our_impact_counter.start();
+                 } else {
+                 console.error(our_impact_counter.error);
+                 }
+             }, 1000);
           
-       }
-       scrolled++;
-       if ($(this).scrollTop() > 50 ) {
-           $('.scrolltop:hidden').stop(true, true).fadeIn();
-       } else {
-           $('.scrolltop').stop(true, true).fadeOut();
-       }
-
-       if ($(window).scrollTop() >= 46) {
-           $('.sticky-header').addClass('fixed-header');
-        }
-        else {
-           $('.sticky-header').removeClass('fixed-header');
-        }
-   });
-   $(function(){$(".scroll").click(function(){$("html,body").animate({scrollTop:$("#glm-main-header").offset().top},"1000");return false})})
-
-   $("#block-3, #block-4").wrapAll(' <div id="small-blocks" class="row collapse">');
-   $("#block-2").wrap('<div id="med-block" class="row collapse">');
-   $("#small-blocks, #med-block").wrapAll('<div class="small-12 large-6 columns">');
-
-   var event_feed      = $("#event-feed");
-   var category_image  = $("#glm-category-images-list");
-   event_feed.addClass("feed");
-   category_image.addClass("category-feed");
-
-   function slickening(el, slides, autoplay){
-       if(el.hasClass('slick-initialized') ) {
-           el.slick('unslick')
-       }
-       el.slick({
-           infinite: true,
-           slidesToShow: slides,
-           slidesToScroll: 1,
-           autoplay: autoplay,
-           arrows: true,
-
-       });
-   }
-   function check_window_width(){
-       if( $('.slick-track').length > 0 ){
-           $('.slick-track').addClass("row collapse");
-       }
-       if($(window).width() > 1023){
-
-           slickening( $('.feed'), 3, false );
-       } else if($(window).width() < 1025 && $(window).width() > 639){
-           if( $(".feed").hasClass('slick-initialized') ) {
-               $(".feed").slick('unslick');
-           }
-           slickening( $('.feed'), 2, false );
-       } else if($(window).width() < 641 && $(window).width() > 319){
-           if( $(".feed").hasClass('slick-initialized') ) {
-               $(".feed").slick('unslick');
-           }
-           slickening( $('.feed'), 1, false );
-       }
-   }
-
-   check_window_width();
-   $(window).resize(function () {
-       check_window_width();
-      
-   });
-
-
-   // remove #/gallery/recent from url to track current page
-   var url = window.location.href.replace("#/gallery/recent", "");
-
-   // 'current' class style to sidebar item that matches the current url
-     $('#side-links ul.sidebar li a').each(function() {
-       if ($(this).prop('href') == url) {
-           $(this).addClass('current');
-       }
-       if($(this).attr("class") === "current"){
-           $(this).parent("li").addClass("current");
-       }
-   });
-   $("#sitemap_pages").find("small").contents().unwrap();
-   $("#sitemap_posts").find("small").contents().unwrap();
-
-   // THIS SECTION CONTAINS DUPLICATE CODE THAT NEEDS TO BE REFACTORED
-   // if( $('.slick-track').length > 0 ){
-       $('.slick-track').addClass("row collapse");
-       if( $('.slick-track').length > 0 ){
-               $('.slick-track').addClass("row collapse");
-      
-           if( $(window).width() > 1023){
-               $('.featured-event-details').each(function(index, value){
-                       var height  = $(this).outerHeight();
-                   $(this).css("bottom", "-"+height+"px");
-                   })
+             window.setTimeout(function(){$('.blur-container').children("span:nth-child(3)").addClass("in-sight");}, 600);
+             our_impact_seen         = true;
+         }
       
-                   var image;
-               $('.featured-event').hover(
-                   function(){
-                       var details         = $(this).find('.featured-event-details');
-
-                       var details_height  = details.outerHeight();
-                       $(this).data("top", details_height);
-                       image           = $(this).find('.front-page-event-image');
-
-                       image.animate({bottom:details_height}, 400, function() {
-                           //callback
-                       });
-                   }, function(){
-                       details_height = $(this).data("top");
-                       image.animate({bottom:0}, 400, function() {
-                           //callback
-                       });
-                   }
-               );
-           }
-       }
-       if( $(window).width() > 1023){
-           $('.front-page-post-content-container').each(function(index, value){
-               var title_height = $(this).find('h2').find('a').outerHeight();
-               var height  = $(this).outerHeight();
-               var offset = height - (title_height + 10);
-               $(this).css("bottom", "-"+offset+"px");
-           })
-
-           var image;
-           $('.home-feed-post').hover(
-               function(){
-                   var details         = $(this).find('.front-page-post-content-container');
-                   var details_height  = details.outerHeight();
-                   $(this).data("top", details_height);
-                   image           = $(this).find('.front-page-blog-image');
-                   image.animate({bottom:details_height}, 400, function() {
-                       //callback
-                   });
-               }, function(){
-                   details_height = $(this).data("top");
-                   image.animate({bottom:0}, 400, function() {
-                       //callback
-                   });
-               }
-           );
-       }
-   // }
-   $(".menu-icon").on("click", function(){
-       $('#oc-overlay').fadeIn();
-   })
-   $("#menu-icon-close").on("click", function(){
-       $('#oc-overlay').fadeOut();
-   })
-   // checking if the video is currently playing
-   Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
-       get: function(){
-           return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2);
-       }
-   })
-   let video;
-   if($(window).width() > 1023 ){
-       video = $(".parallax-video").find('video');
-       video = video[0];
-   } else {
-       video = $("#front-page-video");
-       video = video[0];
-   }
-   $("#pause-video").on("click", function(){
-       if( video.playing ){
-           video.pause();
-           $(this).text('PLAY');
-       }else{
-           video.play();
-           $(this).text('PAUSE');
-        }
-   });
-   $("#restart-video").on("click", function(){
-       video.pause();
-       video.currentTime = 0;
-       video.load();
-   });
-
-   $('.home-feed-post').on('click', function(){
-       window.location = $(this).data('url');
-   })
-});
-
-
+     }
+     scrolled++;
+     if ($(this).scrollTop() > 50 ) {
+         $('.scrolltop:hidden').stop(true, true).fadeIn();
+     } else {
+         $('.scrolltop').stop(true, true).fadeOut();
+     }
+
+     if ($(window).scrollTop() >= 46) {
+         $('.sticky-header').addClass('fixed-header');
+      }
+      else {
+         $('.sticky-header').removeClass('fixed-header');
+      }
+ });
+ $(function(){$(".scroll").click(function(){$("html,body").animate({scrollTop:$("#glm-main-header").offset().top},"1000");return false})})
+
+ $("#block-3, #block-4").wrapAll(' <div id="small-blocks" class="row collapse">');
+ $("#block-2").wrap('<div id="med-block" class="row collapse">');
+ $("#small-blocks, #med-block").wrapAll('<div class="small-12 large-6 columns">');
+
+ var event_feed      = $("#event-feed");
+ var category_image  = $("#glm-category-images-list");
+ event_feed.addClass("feed");
+ category_image.addClass("category-feed");
+
+ function slickening(el, slides, autoplay){
+     if(el.hasClass('slick-initialized') ) {
+         el.slick('unslick')
+     }
+     el.slick({
+         infinite: true,
+         slidesToShow: slides,
+         slidesToScroll: 1,
+         autoplay: autoplay,
+         arrows: true,
+
+     });
+ }
+ function check_window_width(){
+     if( $('.slick-track').length > 0 ){
+         $('.slick-track').addClass("row collapse");
+     }
+     if($(window).width() > 1023){
+
+         slickening( $('.feed'), 3, false );
+     } else if($(window).width() < 1025 && $(window).width() > 639){
+         if( $(".feed").hasClass('slick-initialized') ) {
+             $(".feed").slick('unslick');
+         }
+         slickening( $('.feed'), 2, false );
+     } else if($(window).width() < 641 && $(window).width() > 319){
+         if( $(".feed").hasClass('slick-initialized') ) {
+             $(".feed").slick('unslick');
+         }
+         slickening( $('.feed'), 1, false );
+     }
+ }
+
+ check_window_width();
+ $(window).resize(function () {
+     check_window_width();
+  
+ });
+
+
+ // remove #/gallery/recent from url to track current page
+ var url = window.location.href.replace("#/gallery/recent", "");
+
+ // 'current' class style to sidebar item that matches the current url
+   $('#side-links ul.sidebar li a').each(function() {
+     if ($(this).prop('href') == url) {
+         $(this).addClass('current');
+     }
+     if($(this).attr("class") === "current"){
+         $(this).parent("li").addClass("current");
+     }
+ });
+ $("#sitemap_pages").find("small").contents().unwrap();
+ $("#sitemap_posts").find("small").contents().unwrap();
+
+ // THIS SECTION CONTAINS DUPLICATE CODE THAT NEEDS TO BE REFACTORED
+ // if( $('.slick-track').length > 0 ){
+     $('.slick-track').addClass("row collapse");
+     if( $('.slick-track').length > 0 ){
+             $('.slick-track').addClass("row collapse");
+  
+         if( $(window).width() > 1023){
+             $('.featured-event-details').each(function(index, value){
+                     var height  = $(this).outerHeight();
+                 $(this).css("bottom", "-"+height+"px");
+                 })
+  
+                 var image;
+             $('.featured-event').hover(
+                 function(){
+                     var details         = $(this).find('.featured-event-details');
+
+                     var details_height  = details.outerHeight();
+                     $(this).data("top", details_height);
+                     image           = $(this).find('.front-page-event-image');
+
+                     image.animate({bottom:details_height}, 400, function() {
+                         //callback
+                     });
+                 }, function(){
+                     details_height = $(this).data("top");
+                     image.animate({bottom:0}, 400, function() {
+                         //callback
+                     });
+                 }
+             );
+         }
+     }
+     if( $(window).width() > 1023){
+         $('.front-page-post-content-container').each(function(index, value){
+             var title_height = $(this).find('h2').find('a').outerHeight();
+             var height  = $(this).outerHeight();
+             var offset = height - (title_height + 10);
+             $(this).css("bottom", "-"+offset+"px");
+         })
+
+         var image;
+         $('.home-feed-post').hover(
+             function(){
+                 var details         = $(this).find('.front-page-post-content-container');
+                 var details_height  = details.outerHeight();
+                 $(this).data("top", details_height);
+                 image           = $(this).find('.front-page-blog-image');
+                 image.animate({bottom:details_height}, 400, function() {
+                     //callback
+                 });
+             }, function(){
+                 details_height = $(this).data("top");
+                 image.animate({bottom:0}, 400, function() {
+                     //callback
+                 });
+             }
+         );
+     }
+ // }
+ $(".menu-icon").on("click", function(){
+     $('#oc-overlay').fadeIn();
+ })
+ $("#menu-icon-close").on("click", function(){
+     $('#oc-overlay').fadeOut();
+ })
+ // checking if the video is currently playing
+ Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
+     get: function(){
+         return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2);
+     }
+ })
+ let video;
+ if($(window).width() > 1023 ){
+     video = $(".parallax-video").find('video');
+     video = video[0];
+ } else {
+     video = $("#front-page-video");
+     video = video[0];
+ }
+ $("#pause-video").on("click", function(){
+     if( video.playing ){
+         video.pause();
+         $(this).text('PLAY');
+     }else{
+         video.play();
+         $(this).text('PAUSE');
+      }
+ });
+ $("#restart-video").on("click", function(){
+     video.pause();
+     video.currentTime = 0;
+     video.load();
+ });
+
+ $('.home-feed-post').on('click', function(){
+     window.location = $(this).data('url');
+ })
+});
\ No newline at end of file
index 1710408..962e5dc 100644 (file)
@@ -8,355 +8,364 @@ $(document).ready(function () {
 
    // console.log(menu_items)
    oc_menu.children('ul').on("click", '> li', function(event){
-       // console.log(event.target);
-       // console.log($(this));
+     // console.log(event.target);
+     // console.log($(this));
    })
-
+   let collapseMenu;
    menu_items.each(function(){
        let menuThis = $(this);
-      
+  
        menuThis.on("click", function(){
            other_menu = $(this).closest('ul.sub-menu-section').siblings('ul.sub-menu-section').not(".oc-home-link");
        })
        if( $(this).children('ul').length > 0 ){
            let menuParent = $(this).parent();
-  
            $(this).on("click", function(e){
+               console.log($(this).parent())
+               if( $(this).parent().hasClass('sub-menu-section') ){
+                  collapseMenu = true;
+               }
+               else{
+                   collapseMenu = false;
+               }
+               e.stopImmediatePropagation();
+              
                // collapse the nav menu that isn't in focus (primary or secondary)
-               other_menu.toggleClass("oc-hidden");
-
+               if( $('.oc-open').length > 0 ){
+                  childMenuVisible = true;
+               } else {
+                  childMenuVisible = false;
+               }
+            
                // alter the orientation of the nav arrow, it's the only el that uses a plain open class instead of oc-open
                $(this).children('a').toggleClass('open');
-               e.stopImmediatePropagation();
-               // problem is here, this is a blanket toggle which affects sub menus unintentionally
                $(this).children('a').siblings('ul').toggleClass('oc-open');
-
+               console.log(childMenuVisible);
+               if( collapseMenu && childMenuVisible){
+                   other_menu.toggleClass("oc-hidden"); 
+                   // $(this).children('a').siblings('ul').toggleClass('oc-open');         
+               } else if( collapseMenu){
+                   other_menu.toggleClass("oc-hidden");
+               }
                // For animation purposes
                $(this).toggleClass('oc-expanded');
                $(this).siblings().toggleClass("oc-collapsed");
                $('.oc-overlay').animate({ scrollTop: 0 }, "slow");
-           })
-
-           $(this).children('a').on('click', function(e){
-               e.preventDefault();
-           })
-
-       } else {
-           let url = $(this).children('a').attr('href');
-           $(this).on("click", function(){
-               window.location = url;
-           })
-       }
-   });
-
-
-
-
-
-   $('ul.children').each(function () {
-       $(this).before('<a class="toggle" href="#"></a>');
-   });
-   $('#glm-member-password-lost-link').click(function() {
-       $('#glm-member-password-lost-form').show();
-   });
-  
-
-   $('.top-bar-section').find('ul.sub-menu.dropdown').each(function (){
-       var menuImg = $(this).parent('li').prop('id');
-       var menuNum = menuImg.match(/\d+/)[0];
-       var menuImgSrc = 'img_for_menu_' + menuNum;
-       if (window['img_for_menu_' + menuNum]) {
-           $(this).find('li.image-placeholder').html('<img src="' + eval(menuImgSrc) + '">');
-       } else {
-           $(this).find('li.image-placeholder').parent('ul').addClass('no-image-subul');
-           $(this).find('li.image-placeholder').remove();
-       }
-       //console.log('ul = ' + menuImg);
-       //console.log('menu-id = ' + menuNum);
-   });
-
-   $("#searchIcon").click(function(){
-       if($("#topSearchForm").css("display") == "none"){
+         })
+
+         $(this).children('a').on('click', function(e){
+             e.preventDefault();
+         })
+
+     } else {
+         let url = $(this).children('a').attr('href');
+         $(this).on("click", function(){
+             window.location = url;
+         })
+     }
+ });
+
+ $('ul.children').each(function () {
+     $(this).before('<a class="toggle" href="#"></a>');
+ });
+ $('#glm-member-password-lost-link').click(function() {
+     $('#glm-member-password-lost-form').show();
+ });
+
+ $('.top-bar-section').find('ul.sub-menu.dropdown').each(function (){
+     var menuImg = $(this).parent('li').prop('id');
+     var menuNum = menuImg.match(/\d+/)[0];
+     var menuImgSrc = 'img_for_menu_' + menuNum;
+     if (window['img_for_menu_' + menuNum]) {
+         $(this).find('li.image-placeholder').html('<img src="' + eval(menuImgSrc) + '">');
+     } else {
+         $(this).find('li.image-placeholder').parent('ul').addClass('no-image-subul');
+         $(this).find('li.image-placeholder').remove();
+     }
+     //console.log('ul = ' + menuImg);
+     //console.log('menu-id = ' + menuNum);
+ });
+
+ $("#searchIcon").click(function(){
+     if($("#topSearchForm").css("display") == "none"){
 //           $("#searchform").css("display", "inline");
-           $("#topSearchForm").toggle("slide");
-           $("#searchIcon").css("visibility", "hidden");
-       }
-        $("#lar-search").focus();
-   });
-   $("#lar-search").blur(function(){
-       $("#topSearchForm").toggle("slide");
-       $("#searchIcon").css("visibility", "visible");
-   });
-
-
-   // MOBILE SEARCH
-   var right = $('#mobile-search-form').offset().right;
-   $("#mobile-search").on("click", function(){
-       $("#mobile-search-form").css({right:right})  // Set the left to its calculated position
-       .animate({"right":"0px"}, "slow");
-   });
-   $(".mobile-search-close").on("click", function(){
-       $("#mobile-search-form").css({right:right})  // Set the left to its calculated position
-       .animate({"right":"-100%"}, "slow");
-   });
-   var countup_options = {
-       useEasing: true,
-       useGrouping: true,
-       separator: ',',
-       decimal: '.',
-   };
-   $.fn.isInViewport = function(offset) {
-       var elementTop      = $(this).offset().top;
-       var elementBottom   = elementTop + $(this).outerHeight();
-       var viewportTop     = $(window).scrollTop();
-       var viewportBottom  = viewportTop + $(window).height();
-       var center          = (viewportBottom + viewportTop) / 2 + parseInt(offset);
-       return [elementBottom > viewportTop && elementTop < center,$(this)];
-   };
-   var blocks = [$('#block-1'),$('#block-2'),$('#block-3'),$('#block-4')];
-   var posts  = $('.home-feed-post');
-  
-   var blog_position = $("#home-feed-posts").position();
-   var scrolled = 0;
-   var the_number = parseInt($('.first-blur').text());
-
-   var our_impact_seen         = false;
-   $(window).on("scroll", function() {
-       var page_position  = $(window).scrollTop();     
-           if( $(window).width() < 1024 ){
-               $.each(blocks, function(){
-                   if( $(this).length > 0){
-                       var test_scroll = $(this).isInViewport(-75);
-                      
-                       if( test_scroll[0]){
-                           $(this).find(".overlay").addClass('mobile-overlay');
-                           $(this).find(".overlay").css("background-color", "rbga(0,0,0, .7)");
-                       }else{
-                           $(this).find(".overlay").removeClass('mobile-overlay');
-                           $(this).find(".overlay").css("background-color", "rbga(0,0,0, 0)");
-                       }
-                   }
-               });
-               $.each(posts, function(){
+         $("#topSearchForm").toggle("slide");
+         $("#searchIcon").css("visibility", "hidden");
+     }
+      $("#lar-search").focus();
+ });
+ $("#lar-search").blur(function(){
+     $("#topSearchForm").toggle("slide");
+     $("#searchIcon").css("visibility", "visible");
+ });
+
+
+ // MOBILE SEARCH
+ var right = $('#mobile-search-form').offset().right;
+ $("#mobile-search").on("click", function(){
+     $("#mobile-search-form").css({right:right})  // Set the left to its calculated position
+     .animate({"right":"0px"}, "slow");
+ });
+ $(".mobile-search-close").on("click", function(){
+     $("#mobile-search-form").css({right:right})  // Set the left to its calculated position
+     .animate({"right":"-100%"}, "slow");
+ });
+ var countup_options = {
+     useEasing: true,
+     useGrouping: true,
+     separator: ',',
+     decimal: '.',
+ };
+ $.fn.isInViewport = function(offset) {
+     var elementTop      = $(this).offset().top;
+     var elementBottom   = elementTop + $(this).outerHeight();
+     var viewportTop     = $(window).scrollTop();
+     var viewportBottom  = viewportTop + $(window).height();
+     var center          = (viewportBottom + viewportTop) / 2 + parseInt(offset);
+     return [elementBottom > viewportTop && elementTop < center,$(this)];
+ };
+ var blocks = [$('#block-1'),$('#block-2'),$('#block-3'),$('#block-4')];
+ var posts  = $('.home-feed-post');
+  var blog_position = $("#home-feed-posts").position();
+ var scrolled = 0;
+ var the_number = parseInt($('.first-blur').text());
+
+ var our_impact_seen         = false;
+ $(window).on("scroll", function() {
+     var page_position  = $(window).scrollTop();   
+         if( $(window).width() < 1024 ){
+             $.each(blocks, function(){
+                 if( $(this).length > 0){
+                     var test_scroll = $(this).isInViewport(-75);
                   
-                   if( $(this).length > 0){
-                      
-                       var test_scroll = $(this).isInViewport(-75);
-                       console.log( test_scroll[0] );
-                       if( test_scroll[0]){
-                           $(this).find(".overlay").addClass('blog-overlay');
-                           $(this).find(".overlay").css("background-color", "rbga(0,0,0, .7)");
-                       }else{
-                           $(this).find(".overlay").removeClass('blog-overlay');
-                           $(this).find(".overlay").css("background-color", "rbga(0,0,0, 0)");
-                       }
-                   }
-               });
-           }
-           if($("#home-feed-posts").length ){
-               if($("#home-feed-posts").isInViewport(100)[0]){
-                   $('#home-feed-posts').css("opacity", 1);
-                   $('#home-feed-posts').addClass("fadeInUp");
-               }
-           }
-
-       if( $('.blur-action').length > 0 ){
-           if( $(".blur-action").isInViewport(100)[0] && our_impact_seen == false  ){
-               $('.blur-container').children('span:first-child').addClass("in-sight");
-
-               window.setTimeout(function(){
-                   $('.first-blur').animate({opacity: 1}, 200);
-                   var our_impact_counter = new CountUp('first-blur', 0, parseInt(the_number), 0, 2.5, countup_options);
-                   if (!our_impact_counter.error) {
-                   our_impact_counter.start();
-                   } else {
-                   console.error(our_impact_counter.error);
-                   }
-               }, 1000);
+                     if( test_scroll[0]){
+                         $(this).find(".overlay").addClass('mobile-overlay');
+                         $(this).find(".overlay").css("background-color", "rbga(0,0,0, .7)");
+                     }else{
+                         $(this).find(".overlay").removeClass('mobile-overlay');
+                         $(this).find(".overlay").css("background-color", "rbga(0,0,0, 0)");
+                     }
+                 }
+             });
+             $.each(posts, function(){
               
-               window.setTimeout(function(){$('.blur-container').children("span:nth-child(3)").addClass("in-sight");}, 600);
-               our_impact_seen         = true;
-           }
+                 if( $(this).length > 0){
+                  
+                     var test_scroll = $(this).isInViewport(-75);
+                     console.log( test_scroll[0] );
+                     if( test_scroll[0]){
+                         $(this).find(".overlay").addClass('blog-overlay');
+                         $(this).find(".overlay").css("background-color", "rbga(0,0,0, .7)");
+                     }else{
+                         $(this).find(".overlay").removeClass('blog-overlay');
+                         $(this).find(".overlay").css("background-color", "rbga(0,0,0, 0)");
+                     }
+                 }
+             });
+         }
+         if($("#home-feed-posts").length ){
+             if($("#home-feed-posts").isInViewport(100)[0]){
+                 $('#home-feed-posts').css("opacity", 1);
+                 $('#home-feed-posts').addClass("fadeInUp");
+             }
+         }
+
+     if( $('.blur-action').length > 0 ){
+         if( $(".blur-action").isInViewport(100)[0] && our_impact_seen == false  ){
+             $('.blur-container').children('span:first-child').addClass("in-sight");
+
+             window.setTimeout(function(){
+                 $('.first-blur').animate({opacity: 1}, 200);
+                 var our_impact_counter = new CountUp('first-blur', 0, parseInt(the_number), 0, 2.5, countup_options);
+                 if (!our_impact_counter.error) {
+                 our_impact_counter.start();
+                 } else {
+                 console.error(our_impact_counter.error);
+                 }
+             }, 1000);
           
-       }
-       scrolled++;
-       if ($(this).scrollTop() > 50 ) {
-           $('.scrolltop:hidden').stop(true, true).fadeIn();
-       } else {
-           $('.scrolltop').stop(true, true).fadeOut();
-       }
-
-       if ($(window).scrollTop() >= 46) {
-           $('.sticky-header').addClass('fixed-header');
-        }
-        else {
-           $('.sticky-header').removeClass('fixed-header');
-        }
-   });
-   $(function(){$(".scroll").click(function(){$("html,body").animate({scrollTop:$("#glm-main-header").offset().top},"1000");return false})})
-
-   $("#block-3, #block-4").wrapAll(' <div id="small-blocks" class="row collapse">');
-   $("#block-2").wrap('<div id="med-block" class="row collapse">');
-   $("#small-blocks, #med-block").wrapAll('<div class="small-12 large-6 columns">');
-
-   var event_feed      = $("#event-feed");
-   var category_image  = $("#glm-category-images-list");
-   event_feed.addClass("feed");
-   category_image.addClass("category-feed");
-
-   function slickening(el, slides, autoplay){
-       if(el.hasClass('slick-initialized') ) {
-           el.slick('unslick')
-       }
-       el.slick({
-           infinite: true,
-           slidesToShow: slides,
-           slidesToScroll: 1,
-           autoplay: autoplay,
-           arrows: true,
-
-       });
-   }
-   function check_window_width(){
-       if( $('.slick-track').length > 0 ){
-           $('.slick-track').addClass("row collapse");
-       }
-       if($(window).width() > 1023){
-
-           slickening( $('.feed'), 3, false );
-       } else if($(window).width() < 1025 && $(window).width() > 639){
-           if( $(".feed").hasClass('slick-initialized') ) {
-               $(".feed").slick('unslick');
-           }
-           slickening( $('.feed'), 2, false );
-       } else if($(window).width() < 641 && $(window).width() > 319){
-           if( $(".feed").hasClass('slick-initialized') ) {
-               $(".feed").slick('unslick');
-           }
-           slickening( $('.feed'), 1, false );
-       }
-   }
-
-   check_window_width();
-   $(window).resize(function () {
-       check_window_width();
-      
-   });
-
-
-   // remove #/gallery/recent from url to track current page
-   var url = window.location.href.replace("#/gallery/recent", "");
-
-   // 'current' class style to sidebar item that matches the current url
-     $('#side-links ul.sidebar li a').each(function() {
-       if ($(this).prop('href') == url) {
-           $(this).addClass('current');
-       }
-       if($(this).attr("class") === "current"){
-           $(this).parent("li").addClass("current");
-       }
-   });
-   $("#sitemap_pages").find("small").contents().unwrap();
-   $("#sitemap_posts").find("small").contents().unwrap();
-
-   // THIS SECTION CONTAINS DUPLICATE CODE THAT NEEDS TO BE REFACTORED
-   // if( $('.slick-track').length > 0 ){
-       $('.slick-track').addClass("row collapse");
-       if( $('.slick-track').length > 0 ){
-               $('.slick-track').addClass("row collapse");
-      
-           if( $(window).width() > 1023){
-               $('.featured-event-details').each(function(index, value){
-                       var height  = $(this).outerHeight();
-                   $(this).css("bottom", "-"+height+"px");
-                   })
+             window.setTimeout(function(){$('.blur-container').children("span:nth-child(3)").addClass("in-sight");}, 600);
+             our_impact_seen         = true;
+         }
       
-                   var image;
-               $('.featured-event').hover(
-                   function(){
-                       var details         = $(this).find('.featured-event-details');
-
-                       var details_height  = details.outerHeight();
-                       $(this).data("top", details_height);
-                       image           = $(this).find('.front-page-event-image');
-
-                       image.animate({bottom:details_height}, 400, function() {
-                           //callback
-                       });
-                   }, function(){
-                       details_height = $(this).data("top");
-                       image.animate({bottom:0}, 400, function() {
-                           //callback
-                       });
-                   }
-               );
-           }
-       }
-       if( $(window).width() > 1023){
-           $('.front-page-post-content-container').each(function(index, value){
-               var title_height = $(this).find('h2').find('a').outerHeight();
-               var height  = $(this).outerHeight();
-               var offset = height - (title_height + 10);
-               $(this).css("bottom", "-"+offset+"px");
-           })
-
-           var image;
-           $('.home-feed-post').hover(
-               function(){
-                   var details         = $(this).find('.front-page-post-content-container');
-                   var details_height  = details.outerHeight();
-                   $(this).data("top", details_height);
-                   image           = $(this).find('.front-page-blog-image');
-                   image.animate({bottom:details_height}, 400, function() {
-                       //callback
-                   });
-               }, function(){
-                   details_height = $(this).data("top");
-                   image.animate({bottom:0}, 400, function() {
-                       //callback
-                   });
-               }
-           );
-       }
-   // }
-   $(".menu-icon").on("click", function(){
-       $('#oc-overlay').fadeIn();
-   })
-   $("#menu-icon-close").on("click", function(){
-       $('#oc-overlay').fadeOut();
-   })
-   // checking if the video is currently playing
-   Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
-       get: function(){
-           return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2);
-       }
-   })
-   let video;
-   if($(window).width() > 1023 ){
-       video = $(".parallax-video").find('video');
-       video = video[0];
-   } else {
-       video = $("#front-page-video");
-       video = video[0];
-   }
-   $("#pause-video").on("click", function(){
-       if( video.playing ){
-           video.pause();
-           $(this).text('PLAY');
-       }else{
-           video.play();
-           $(this).text('PAUSE');
-        }
-   });
-   $("#restart-video").on("click", function(){
-       video.pause();
-       video.currentTime = 0;
-       video.load();
-   });
-
-   $('.home-feed-post').on('click', function(){
-       window.location = $(this).data('url');
-   })
-});
-
-
+     }
+     scrolled++;
+     if ($(this).scrollTop() > 50 ) {
+         $('.scrolltop:hidden').stop(true, true).fadeIn();
+     } else {
+         $('.scrolltop').stop(true, true).fadeOut();
+     }
+
+     if ($(window).scrollTop() >= 46) {
+         $('.sticky-header').addClass('fixed-header');
+      }
+      else {
+         $('.sticky-header').removeClass('fixed-header');
+      }
+ });
+ $(function(){$(".scroll").click(function(){$("html,body").animate({scrollTop:$("#glm-main-header").offset().top},"1000");return false})})
+
+ $("#block-3, #block-4").wrapAll(' <div id="small-blocks" class="row collapse">');
+ $("#block-2").wrap('<div id="med-block" class="row collapse">');
+ $("#small-blocks, #med-block").wrapAll('<div class="small-12 large-6 columns">');
+
+ var event_feed      = $("#event-feed");
+ var category_image  = $("#glm-category-images-list");
+ event_feed.addClass("feed");
+ category_image.addClass("category-feed");
+
+ function slickening(el, slides, autoplay){
+     if(el.hasClass('slick-initialized') ) {
+         el.slick('unslick')
+     }
+     el.slick({
+         infinite: true,
+         slidesToShow: slides,
+         slidesToScroll: 1,
+         autoplay: autoplay,
+         arrows: true,
+
+     });
+ }
+ function check_window_width(){
+     if( $('.slick-track').length > 0 ){
+         $('.slick-track').addClass("row collapse");
+     }
+     if($(window).width() > 1023){
+
+         slickening( $('.feed'), 3, false );
+     } else if($(window).width() < 1025 && $(window).width() > 639){
+         if( $(".feed").hasClass('slick-initialized') ) {
+             $(".feed").slick('unslick');
+         }
+         slickening( $('.feed'), 2, false );
+     } else if($(window).width() < 641 && $(window).width() > 319){
+         if( $(".feed").hasClass('slick-initialized') ) {
+             $(".feed").slick('unslick');
+         }
+         slickening( $('.feed'), 1, false );
+     }
+ }
+
+ check_window_width();
+ $(window).resize(function () {
+     check_window_width();
+  
+ });
+
+
+ // remove #/gallery/recent from url to track current page
+ var url = window.location.href.replace("#/gallery/recent", "");
+
+ // 'current' class style to sidebar item that matches the current url
+   $('#side-links ul.sidebar li a').each(function() {
+     if ($(this).prop('href') == url) {
+         $(this).addClass('current');
+     }
+     if($(this).attr("class") === "current"){
+         $(this).parent("li").addClass("current");
+     }
+ });
+ $("#sitemap_pages").find("small").contents().unwrap();
+ $("#sitemap_posts").find("small").contents().unwrap();
+
+ // THIS SECTION CONTAINS DUPLICATE CODE THAT NEEDS TO BE REFACTORED
+ // if( $('.slick-track').length > 0 ){
+     $('.slick-track').addClass("row collapse");
+     if( $('.slick-track').length > 0 ){
+             $('.slick-track').addClass("row collapse");
+  
+         if( $(window).width() > 1023){
+             $('.featured-event-details').each(function(index, value){
+                     var height  = $(this).outerHeight();
+                 $(this).css("bottom", "-"+height+"px");
+                 })
+  
+                 var image;
+             $('.featured-event').hover(
+                 function(){
+                     var details         = $(this).find('.featured-event-details');
+
+                     var details_height  = details.outerHeight();
+                     $(this).data("top", details_height);
+                     image           = $(this).find('.front-page-event-image');
+
+                     image.animate({bottom:details_height}, 400, function() {
+                         //callback
+                     });
+                 }, function(){
+                     details_height = $(this).data("top");
+                     image.animate({bottom:0}, 400, function() {
+                         //callback
+                     });
+                 }
+             );
+         }
+     }
+     if( $(window).width() > 1023){
+         $('.front-page-post-content-container').each(function(index, value){
+             var title_height = $(this).find('h2').find('a').outerHeight();
+             var height  = $(this).outerHeight();
+             var offset = height - (title_height + 10);
+             $(this).css("bottom", "-"+offset+"px");
+         })
+
+         var image;
+         $('.home-feed-post').hover(
+             function(){
+                 var details         = $(this).find('.front-page-post-content-container');
+                 var details_height  = details.outerHeight();
+                 $(this).data("top", details_height);
+                 image           = $(this).find('.front-page-blog-image');
+                 image.animate({bottom:details_height}, 400, function() {
+                     //callback
+                 });
+             }, function(){
+                 details_height = $(this).data("top");
+                 image.animate({bottom:0}, 400, function() {
+                     //callback
+                 });
+             }
+         );
+     }
+ // }
+ $(".menu-icon").on("click", function(){
+     $('#oc-overlay').fadeIn();
+ })
+ $("#menu-icon-close").on("click", function(){
+     $('#oc-overlay').fadeOut();
+ })
+ // checking if the video is currently playing
+ Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
+     get: function(){
+         return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2);
+     }
+ })
+ let video;
+ if($(window).width() > 1023 ){
+     video = $(".parallax-video").find('video');
+     video = video[0];
+ } else {
+     video = $("#front-page-video");
+     video = video[0];
+ }
+ $("#pause-video").on("click", function(){
+     if( video.playing ){
+         video.pause();
+         $(this).text('PLAY');
+     }else{
+         video.play();
+         $(this).text('PAUSE');
+      }
+ });
+ $("#restart-video").on("click", function(){
+     video.pause();
+     video.currentTime = 0;
+     video.load();
+ });
+
+ $('.home-feed-post').on('click', function(){
+     window.location = $(this).data('url');
+ })
+});
\ No newline at end of file