From ff394ac1145dde4396596cd1dbd601c93cf86cf0 Mon Sep 17 00:00:00 2001 From: rclations Date: Tue, 6 Sep 2016 13:38:06 -0400 Subject: [PATCH] removing duplicate code for navigation toggle on mobile --- js/navigation.js | 16 ---------------- js/navigation.min.js | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/js/navigation.js b/js/navigation.js index 6182f081d..12b707d09 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -42,22 +42,6 @@ // Open the drop down openMenu = false; - // Handle the tap for the drop down - $('ul.nav').on(mobileEvent + '.largo', 'li', function(event) { - var li = $(event.currentTarget); - - if (!li.is('.open')) { - // The link when the menu is closed - closeOpenMenu(); - li.addClass('open'); - openMenu = li; - } else if ($(event.target).is('b.caret')) { - // The caret when the menu is open - li.removeClass('open'); - openMenu = false; - } - }); - // Call this to close the open menu var closeOpenMenu = function() { if (openMenu) { diff --git a/js/navigation.min.js b/js/navigation.min.js index 2b69cde34..24543deea 100644 --- a/js/navigation.min.js +++ b/js/navigation.min.js @@ -1 +1 @@ -!function(){var a=jQuery,b=function(){return this.scrollTop=a(window).scrollTop(),this.previousScroll=null,this.initialLoad=!0,this.init()};b.prototype.init=function(){return this.enableMobileDropdowns(),this.stickyNavEl=a(".sticky-nav-holder"),this.stickyNavWrapper=a(".sticky-nav-wrapper"),this.mainEl=a("#main"),this.mainNavEl=a("#main-nav"),a(window).width()>768&&this.stickyNavTransition(),this.bindEvents(),setTimeout(this.navOverflow.bind(this),0),this.responsiveNavigation(),this},b.prototype.enableMobileDropdowns=function(){if(Modernizr.touch){var b=/Mobile\/.+Safari/.test(navigator.userAgent)?"touchstart":"click",c=!1;a("ul.nav").on(b+".largo","li",function(b){var e=a(b.currentTarget);e.is(".open")?a(b.target).is("b.caret")&&(e.removeClass("open"),c=!1):(d(),e.addClass("open"),c=e)});var d=function(){c&&(c.removeClass("open"),c=!1)};a("body").on(b,d)}},b.prototype.bindEvents=function(){a(window).resize(this.navOverflow.bind(this)),this.bindStickyNavEvents()},b.prototype.bindStickyNavEvents=function(){var b=this;a.each(Largo.sticky_nav_options,function(a,c){c&&b.stickyNavEl.addClass(a)}),a(window).on("scroll",this.stickyNavScrollCallback.bind(this)),a(window).on("resize",this.stickyNavResizeCallback.bind(this)),this.stickyNavResizeCallback(),this.stickyNavSetOffset()},b.prototype.stickyNavScrollTopHide=function(){if(a(window).scrollTop()<=this.mainEl.offset().top&&this.mainNavEl.is(":visible"))return this.stickyNavEl.removeClass("show"),void clearTimeout(this.scrollTimeout)},b.prototype.stickyNavResizeCallback=function(){a(window).width()<=768||Largo.sticky_nav_options.main_nav_hide_article&&(a("body").hasClass("single")||a("body").hasClass("page"))?(this.stickyNavEl.addClass("show"),this.stickyNavEl.parent().css("height",this.stickyNavEl.outerHeight())):Largo.sticky_nav_options.sticky_nav_display?(this.stickyNavScrollTopHide(),this.stickyNavEl.parent().css("height","")):this.stickyNavEl.parent().css("height",""),this.stickyNavSetOffset(),this.stickyNavTransitionDone()},b.prototype.stickyNavScrollCallback=function(b){if(!(a(window).scrollTop()<0||a(window).scrollTop()+a(window).outerHeight()>=a(document).outerHeight())){var c,d,e=this.scrollDirection();if(this.stickyNavScrollTopHide(),this.stickyNavSetOffset(),this.previousScroll==e||!this.previousScroll)return void(this.previousScroll=e);clearTimeout(this.scrollTimeout),"up"==e?(c=this.stickyNavEl.addClass.bind(this.stickyNavEl,"show"),d=250):"down"==e&&(c=this.stickyNavEl.removeClass.bind(this.stickyNavEl,"show"),d=500),this.scrollTimeout=setTimeout(c,d),this.previousScroll=e}},b.prototype.scrollDirection=function(){var b,c=a(window).scrollTop();return b=c>this.scrollTop?"down":"up",this.scrollTop=c,b},b.prototype.stickyNavSetOffset=function(){a("body").hasClass("admin-bar")&&(a(window).scrollTop()<=a("#wpadminbar").outerHeight()?this.stickyNavEl.css("top",a("#wpadminbar").outerHeight()):this.stickyNavEl.css("top",""))},b.prototype.responsiveNavigation=function(){var b=this;a(".navbar .toggle-nav-bar").each(function(){var c=a(this),d=c.closest(".navbar");c.on("touchstart.toggleNav click.toggleNav",function(e){return"touchstart"==e.type&&c.off("click.toggleNav"),d.toggleClass("open"),a("html").addClass("nav-open"),b.stickyNavSetOffset(),d.find(".nav-shelf").css({top:b.stickyNavEl.position().top+b.stickyNavEl.outerHeight()}),d.hasClass("open")||(d.find(".nav-shelf li.open").removeClass("open"),a("html").removeClass("nav-open")),!1}),d.on("touchstart.toggleNav click.toggleNav",".nav-shelf .caret",function(b){if("none"==c.css("display"))return!1;"touchstart"==b.type&&d.off("click.toggleNav",".nav-shelf .dropdown-toggle");var e=a(b.target).closest("li");return e.hasClass("open")||d.find(".nav-shelf li.open").removeClass("open"),e.toggleClass("open"),!1})})},b.prototype.navOverflow=function(){var b=a("#sticky-nav");if(!b.is(":visible")||a(window).width()<=768)return void this.revertOverflow();var c=b.find(".nav-shelf"),d=b.find(".toggle-nav-bar"),e=b.find(".nav-right"),f=c.outerWidth(),g=e.outerWidth(),h=b.find(".caret").first().outerWidth(),i=(a(window).width(),d.is(":visible"));if(!i){this.stickyNavEl.hasClass("transitioning")||this.stickyNavTransition();var j=0;c.find("ul.nav > li").each(function(){a(this).is(":visible")&&(j+=a(this).outerWidth())});var k=c.find("ul.nav > li#menu-overflow.menu-item-has-children").last();if(!i&&j>f-g-h){if(0==k.length){var l='';k=a(l),k.find("a").click(function(){return!1}),c.find("ul.nav > li.menu-item").last().after(k)}var m=c.find("ul.nav > li.menu-item").last();k.find("ul#menu-more-1").prepend(m),m.addClass("overflowed"),m.data("shelfwidth",f)}else if(k.length){var m=k.find("li").first();m.hasClass("overflowed")&&m.data("shelfwidth") li.menu-item").last().after(m),0==k.find("ul li").length&&k.remove())}var j=0;if(c.find("ul.nav > li").each(function(){a(this).is(":visible")&&(j+=a(this).outerWidth())}),f=c.outerWidth(),g=e.outerWidth(),!i&&j>f-g-h)return"undefined"!=typeof this.navOverflowTimeout&&clearTimeout(this.navOverflowTimeout),void(this.navOverflowTimeout=setTimeout(this.navOverflow.bind(this),0))}this.stickyNavTransitionDone()},b.prototype.stickyNavTransition=function(){this.stickyNavEl.hasClass("transitioning")||this.stickyNavEl.addClass("transitioning")},b.prototype.stickyNavTransitionDone=function(){var a=this;"undefined"!=typeof this.stickyNavTransitionTimeout&&clearTimeout(this.stickyNavTransitionTimeout),this.stickyNavTransitionTimeout=setTimeout(function(){a.stickyNavEl.hasClass("transitioning")&&a.stickyNavEl.removeClass("transitioning")},500)},b.prototype.revertOverflow=function(){var b=a("#sticky-nav"),c=(shelf=b.find(".nav-shelf"),shelf.find("ul.nav > li#menu-overflow.menu-item-has-children").last());c.find("li.overflowed").each(function(a,b){shelf.find("ul.nav > li.menu-item").last().after(b)}),0==c.find("ul li").length&&c.remove()},"undefined"==typeof window.Navigation&&(window.Navigation=b),a(document).ready(function(){new b})}(); \ No newline at end of file +!function(){var a=jQuery,b=function(){return this.scrollTop=a(window).scrollTop(),this.previousScroll=null,this.initialLoad=!0,this.init()};b.prototype.init=function(){return this.enableMobileDropdowns(),this.stickyNavEl=a(".sticky-nav-holder"),this.stickyNavWrapper=a(".sticky-nav-wrapper"),this.mainEl=a("#main"),this.mainNavEl=a("#main-nav"),a(window).width()>768&&this.stickyNavTransition(),this.bindEvents(),setTimeout(this.navOverflow.bind(this),0),this.responsiveNavigation(),this},b.prototype.enableMobileDropdowns=function(){if(Modernizr.touch){var b=/Mobile\/.+Safari/.test(navigator.userAgent)?"touchstart":"click",c=!1,d=function(){c&&(c.removeClass("open"),c=!1)};a("body").on(b,d)}},b.prototype.bindEvents=function(){a(window).resize(this.navOverflow.bind(this)),this.bindStickyNavEvents()},b.prototype.bindStickyNavEvents=function(){var b=this;a.each(Largo.sticky_nav_options,function(a,c){c&&b.stickyNavEl.addClass(a)}),a(window).on("scroll",this.stickyNavScrollCallback.bind(this)),a(window).on("resize",this.stickyNavResizeCallback.bind(this)),this.stickyNavResizeCallback(),this.stickyNavSetOffset()},b.prototype.stickyNavScrollTopHide=function(){if(a(window).scrollTop()<=this.mainEl.offset().top&&this.mainNavEl.is(":visible"))return this.stickyNavEl.removeClass("show"),void clearTimeout(this.scrollTimeout)},b.prototype.stickyNavResizeCallback=function(){a(window).width()<=768||Largo.sticky_nav_options.main_nav_hide_article&&(a("body").hasClass("single")||a("body").hasClass("page"))?(this.stickyNavEl.addClass("show"),this.stickyNavEl.parent().css("height",this.stickyNavEl.outerHeight())):Largo.sticky_nav_options.sticky_nav_display?(this.stickyNavScrollTopHide(),this.stickyNavEl.parent().css("height","")):this.stickyNavEl.parent().css("height",""),this.stickyNavSetOffset(),this.stickyNavTransitionDone()},b.prototype.stickyNavScrollCallback=function(b){if(!(a(window).scrollTop()<0||a(window).scrollTop()+a(window).outerHeight()>=a(document).outerHeight())){var c,d,e=this.scrollDirection();if(this.stickyNavScrollTopHide(),this.stickyNavSetOffset(),this.previousScroll==e||!this.previousScroll)return void(this.previousScroll=e);clearTimeout(this.scrollTimeout),"up"==e?(c=this.stickyNavEl.addClass.bind(this.stickyNavEl,"show"),d=250):"down"==e&&(c=this.stickyNavEl.removeClass.bind(this.stickyNavEl,"show"),d=500),this.scrollTimeout=setTimeout(c,d),this.previousScroll=e}},b.prototype.scrollDirection=function(){var b,c=a(window).scrollTop();return b=c>this.scrollTop?"down":"up",this.scrollTop=c,b},b.prototype.stickyNavSetOffset=function(){a("body").hasClass("admin-bar")&&(a(window).scrollTop()<=a("#wpadminbar").outerHeight()?this.stickyNavEl.css("top",a("#wpadminbar").outerHeight()):this.stickyNavEl.css("top",""))},b.prototype.responsiveNavigation=function(){var b=this;a(".navbar .toggle-nav-bar").each(function(){var c=a(this),d=c.closest(".navbar");c.on("touchstart.toggleNav click.toggleNav",function(e){return"touchstart"==e.type&&c.off("click.toggleNav"),d.toggleClass("open"),a("html").addClass("nav-open"),b.stickyNavSetOffset(),d.find(".nav-shelf").css({top:b.stickyNavEl.position().top+b.stickyNavEl.outerHeight()}),d.hasClass("open")||(d.find(".nav-shelf li.open").removeClass("open"),a("html").removeClass("nav-open")),!1}),d.on("touchstart.toggleNav click.toggleNav",".nav-shelf .caret",function(b){if("none"==c.css("display"))return!1;"touchstart"==b.type&&d.off("click.toggleNav",".nav-shelf .dropdown-toggle");var e=a(b.target).closest("li");return e.hasClass("open")||d.find(".nav-shelf li.open").removeClass("open"),e.toggleClass("open"),!1})})},b.prototype.navOverflow=function(){var b=a("#sticky-nav");if(!b.is(":visible")||a(window).width()<=768)return void this.revertOverflow();var c=b.find(".nav-shelf"),d=b.find(".toggle-nav-bar"),e=b.find(".nav-right"),f=c.outerWidth(),g=e.outerWidth(),h=b.find(".caret").first().outerWidth(),i=(a(window).width(),d.is(":visible"));if(!i){this.stickyNavEl.hasClass("transitioning")||this.stickyNavTransition();var j=0;c.find("ul.nav > li").each(function(){a(this).is(":visible")&&(j+=a(this).outerWidth())});var k=c.find("ul.nav > li#menu-overflow.menu-item-has-children").last();if(!i&&j>f-g-h){if(0==k.length){var l='';k=a(l),k.find("a").click(function(){return!1}),c.find("ul.nav > li.menu-item").last().after(k)}var m=c.find("ul.nav > li.menu-item").last();k.find("ul#menu-more-1").prepend(m),m.addClass("overflowed"),m.data("shelfwidth",f)}else if(k.length){var m=k.find("li").first();m.hasClass("overflowed")&&m.data("shelfwidth") li.menu-item").last().after(m),0==k.find("ul li").length&&k.remove())}var j=0;if(c.find("ul.nav > li").each(function(){a(this).is(":visible")&&(j+=a(this).outerWidth())}),f=c.outerWidth(),g=e.outerWidth(),!i&&j>f-g-h)return"undefined"!=typeof this.navOverflowTimeout&&clearTimeout(this.navOverflowTimeout),void(this.navOverflowTimeout=setTimeout(this.navOverflow.bind(this),0))}this.stickyNavTransitionDone()},b.prototype.stickyNavTransition=function(){this.stickyNavEl.hasClass("transitioning")||this.stickyNavEl.addClass("transitioning")},b.prototype.stickyNavTransitionDone=function(){var a=this;"undefined"!=typeof this.stickyNavTransitionTimeout&&clearTimeout(this.stickyNavTransitionTimeout),this.stickyNavTransitionTimeout=setTimeout(function(){a.stickyNavEl.hasClass("transitioning")&&a.stickyNavEl.removeClass("transitioning")},500)},b.prototype.revertOverflow=function(){var b=a("#sticky-nav"),c=(shelf=b.find(".nav-shelf"),shelf.find("ul.nav > li#menu-overflow.menu-item-has-children").last());c.find("li.overflowed").each(function(a,b){shelf.find("ul.nav > li.menu-item").last().after(b)}),0==c.find("ul li").length&&c.remove()},"undefined"==typeof window.Navigation&&(window.Navigation=b),a(document).ready(function(){new b})}(); \ No newline at end of file