fixing the oc menu to open when clicking on the nav item
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 2 Nov 2018 19:42:07 +0000 (15:42 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 2 Nov 2018 19:42:07 +0000 (15:42 -0400)
js/app.js
js/custom/pageSetup.js
lib/menu-walker.php

index eb243d9..46fe3e4 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -17,10 +17,47 @@ $(document).ready(function () {
     $('ul.children').each(function () {
         $(this).before('<a class="toggle" href="#"></a>');
     });
-    $('a.toggle').click('click', function () {
-        $(this).toggleClass('open');
-        $(this).siblings('ul').toggleClass('open');
+    // $('a.toggle').click('click', function () {
+    //     $(this).toggleClass('open');
+    //     $(this).siblings('ul').toggleClass('open');
+    // });
+    $('a.toggle').on("click", function (e) {
+        // $(this).toggleClass('open');
+        // $(this).siblings('ul').toggleClass('open');
+        if( $(this).hasClass("open") ){
+            $(this).removeClass("open")
+            $(this).siblings('ul').removeClass("open");
+        }else{
+     
+            $(this).addClass("open")
+            $(this).siblings('ul').addClass("open");
+        }
+
     });
+    // if( $(window).width() < 1024){
+    //     if(window.glmData.location){
+    //         $('a.toggle').trigger("click");
+    //         $('.off-canvas-wrap').foundation('offcanvas', 'show', 'move-right');
+    //     }
+    // }
+    $('.left-off-canvas-list').find('.menu-item-has-children > a:not(.toggle)').on("click", function(e){
+    
+        e.preventDefault();
+        // $(this).children('a.toggle').toggleClass('open');
+        // $(this).children('ul').toggleClass('open');
+        if( $(this).next().hasClass("open") ){
+            $(this).next().removeClass("open")
+            $(this).siblings('ul').removeClass("open");
+        }else{
+     
+            $(this).next().addClass("open")
+            $(this).siblings('ul').addClass("open");
+        }
+    })
+    
+    $(".menu-item:not(.menu-item-has-children) > a:not(.toggle)").on("click", function(e){
+        e.stopPropagation();
+    })
     $('.top-bar-section').find('ul.sub-menu.dropdown').each(function (){
         var menuImg = $(this).parent('li').prop('id');
         var menuNum = menuImg.match(/\d+/)[0];
@@ -38,23 +75,43 @@ $(document).ready(function () {
         $('#glm-member-password-lost-form').show();
     });
 
-  
+    $('.search-icon').toggle(function() { 
+        $('.header-search').animate({ width:'150px' }); 
+        $('.header-search-input').css("border", "2px solid " + d_blue)
+    }, function() {
+        $('.header-search').animate({ width:'0' }); 
+        $('.header-search-input').css("border", "2px solid transparent")
+    });
+
+    $('.header-search-input').on("blur", function(){
+        console.log("blur");
+        if( $('.header-search').length > 0 ){
+            console.log("Still open");
+        } else{
+            console.log("closed");
+        }
+    });
 
-        $('.search-icon').toggle(function() { 
-            $('.header-search').animate({ width:'150px' }); 
-            $('.header-search-input').css("border", "2px solid " + d_blue)
-        }, function() {
-            $('.header-search').animate({ width:'0' }); 
-            $('.header-search-input').css("border", "2px solid transparent")
+    var main_nav_top_level = $('.top-bar-section').children('ul').children('li.menu-item-has-children');
+    main_nav_top_level.each(function() {
+        $(this).on("click",  function(event){
+            var parentId = $(this).attr("id");
+            var childId = $(event.target).parent().attr("id")
+            if( parentId === childId ){
+                event.stopPropagation();
+                event.preventDefault();
+            }
         });
-    
-        $('.header-search-input').on("blur", function(){
-            console.log("blur");
-            if( $('.header-search').length > 0 ){
-                console.log("Still open");
-            } else{
-                console.log("closed");
+    });
+
+    var main_nav_top_level_oc = $('.left-off-canvas-list').children('ul').children('li.menu-item-has-children');
+    main_nav_top_level_oc.each(function() {
+        $(this).on("click",  function(event){
+            let isParent = $(event.target).parent().hasClass("oc_parent");
+            if( isParent ){
+                event.stopPropagation();
+                event.preventDefault();
             }
-        })
-    
+        });
+    });
 });
index 0cd4206..334780c 100644 (file)
@@ -8,10 +8,47 @@ $(document).ready(function () {
     $('ul.children').each(function () {
         $(this).before('<a class="toggle" href="#"></a>');
     });
-    $('a.toggle').click('click', function () {
-        $(this).toggleClass('open');
-        $(this).siblings('ul').toggleClass('open');
+    // $('a.toggle').click('click', function () {
+    //     $(this).toggleClass('open');
+    //     $(this).siblings('ul').toggleClass('open');
+    // });
+    $('a.toggle').on("click", function (e) {
+        // $(this).toggleClass('open');
+        // $(this).siblings('ul').toggleClass('open');
+        if( $(this).hasClass("open") ){
+            $(this).removeClass("open")
+            $(this).siblings('ul').removeClass("open");
+        }else{
+     
+            $(this).addClass("open")
+            $(this).siblings('ul').addClass("open");
+        }
+
     });
+    // if( $(window).width() < 1024){
+    //     if(window.glmData.location){
+    //         $('a.toggle').trigger("click");
+    //         $('.off-canvas-wrap').foundation('offcanvas', 'show', 'move-right');
+    //     }
+    // }
+    $('.left-off-canvas-list').find('.menu-item-has-children > a:not(.toggle)').on("click", function(e){
+    
+        e.preventDefault();
+        // $(this).children('a.toggle').toggleClass('open');
+        // $(this).children('ul').toggleClass('open');
+        if( $(this).next().hasClass("open") ){
+            $(this).next().removeClass("open")
+            $(this).siblings('ul').removeClass("open");
+        }else{
+     
+            $(this).next().addClass("open")
+            $(this).siblings('ul').addClass("open");
+        }
+    })
+    
+    $(".menu-item:not(.menu-item-has-children) > a:not(.toggle)").on("click", function(e){
+        e.stopPropagation();
+    })
     $('.top-bar-section').find('ul.sub-menu.dropdown').each(function (){
         var menuImg = $(this).parent('li').prop('id');
         var menuNum = menuImg.match(/\d+/)[0];
@@ -29,23 +66,43 @@ $(document).ready(function () {
         $('#glm-member-password-lost-form').show();
     });
 
-  
+    $('.search-icon').toggle(function() { 
+        $('.header-search').animate({ width:'150px' }); 
+        $('.header-search-input').css("border", "2px solid " + d_blue)
+    }, function() {
+        $('.header-search').animate({ width:'0' }); 
+        $('.header-search-input').css("border", "2px solid transparent")
+    });
+
+    $('.header-search-input').on("blur", function(){
+        console.log("blur");
+        if( $('.header-search').length > 0 ){
+            console.log("Still open");
+        } else{
+            console.log("closed");
+        }
+    });
 
-        $('.search-icon').toggle(function() { 
-            $('.header-search').animate({ width:'150px' }); 
-            $('.header-search-input').css("border", "2px solid " + d_blue)
-        }, function() {
-            $('.header-search').animate({ width:'0' }); 
-            $('.header-search-input').css("border", "2px solid transparent")
+    var main_nav_top_level = $('.top-bar-section').children('ul').children('li.menu-item-has-children');
+    main_nav_top_level.each(function() {
+        $(this).on("click",  function(event){
+            var parentId = $(this).attr("id");
+            var childId = $(event.target).parent().attr("id")
+            if( parentId === childId ){
+                event.stopPropagation();
+                event.preventDefault();
+            }
         });
-    
-        $('.header-search-input').on("blur", function(){
-            console.log("blur");
-            if( $('.header-search').length > 0 ){
-                console.log("Still open");
-            } else{
-                console.log("closed");
+    });
+
+    var main_nav_top_level_oc = $('.left-off-canvas-list').children('ul').children('li.menu-item-has-children');
+    main_nav_top_level_oc.each(function() {
+        $(this).on("click",  function(event){
+            let isParent = $(event.target).parent().hasClass("oc_parent");
+            if( isParent ){
+                event.stopPropagation();
+                event.preventDefault();
             }
-        })
-    
+        });
+    });
 });
index f5604f9..64282d6 100644 (file)
@@ -50,7 +50,7 @@ class Glm_Theme_Off_Canvas_Walker extends Walker_Nav_Menu {
     function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
         $element->has_children = ! empty( $children_elements[ $element->ID ] );
         $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : '';
-        $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'page_item_has_children' : '';
+        $element->classes[] = ( $element->has_children && 1 !== $max_depth ) ? 'page_item_has_children oc_parent' : '';
         $element->classes[] = 'page_item';
 
         parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );