responsive-menus.min.js 4.3 KB

1234567891011121314151617
  1. /**
  2. * This script adds the accessibility-ready responsive menus Genesis Framework child themes.
  3. *
  4. * @author StudioPress
  5. * @link https://github.com/copyblogger/responsive-menus
  6. * @version 1.1.2
  7. * @license GPL-2.0+
  8. */
  9. var genesisMenuParams="undefined"===typeof genesis_responsive_menu?"":genesis_responsive_menu,genesisMenusUnchecked=genesisMenuParams.menuClasses,genesisMenus={},menusToCombine=[];
  10. (function(m,b,w){function n(){var a=b('button[id^="genesis-mobile-"]').attr("id");if("undefined"!==typeof a){"none"===k(a)&&(b(".menu-toggle, .genesis-responsive-menu .sub-menu-toggle").removeClass("activated").attr("aria-expanded",!1).attr("aria-pressed",!1),b(".genesis-responsive-menu, genesis-responsive-menu .sub-menu").attr("style",""));var d=b(".genesis-responsive-menu .js-superfish"),c="destroy";"function"===typeof d.superfish&&("none"===k(a)&&(c={delay:100,animation:{opacity:"show",height:"show"},
  11. dropShadows:!1,speed:"fast"}),d.superfish(c));p(a);q(a)}}function r(){var a=b(this),d=a.next("nav");a.attr("id","genesis-mobile-"+b(d).attr("class").match(/nav-\w*\b/))}function q(a){if(null!=menusToCombine){var d=menusToCombine[0],c=b(menusToCombine).filter(function(a){if(0<a)return a});"none"!==k(a)?(b.each(c,function(a,c){b(c).find(".menu > li").addClass("moved-item-"+c.replace(".","")).appendTo(d+" ul.genesis-nav-menu")}),b(g(c)).hide()):(b(g(c)).show(),b.each(c,function(a,c){b(".moved-item-"+
  12. c.replace(".","")).appendTo(c+" ul.genesis-nav-menu").removeClass("moved-item-"+c.replace(".",""))}))}}function t(){var a=b(this);h(a,"aria-pressed");h(a,"aria-expanded");a.toggleClass("activated");a.next("nav").slideToggle("fast")}function u(){var a=b(this),d=a.closest(".menu-item").siblings();h(a,"aria-pressed");h(a,"aria-expanded");a.toggleClass("activated");a.next(".sub-menu").slideToggle("fast");d.find(".sub-menu-toggle").removeClass("activated").attr("aria-pressed","false");d.find(".sub-menu").slideUp("fast")}
  13. function p(a){var d=l();0< !b(d).length||b.each(d,function(c,d){var e=d.replace(".",""),f="genesis-"+e,g="genesis-mobile-"+e;"none"==k(a)&&(f="genesis-mobile-"+e,g="genesis-"+e);e=b('.genesis-skip-link a[href="#'+f+'"]');null!==menusToCombine&&d!==menusToCombine[0]&&e.toggleClass("skip-link-hidden");if(0<e.length){var h=e.attr("href"),h=h.replace(f,g);e.attr("href",h)}})}function k(a){a=m.getElementById(a);return window.getComputedStyle(a).getPropertyValue("display")}function h(a,b){a.attr(b,function(a,
  14. b){return"false"===b})}function g(a){return b.map(a,function(a,b){return a}).join(",")}function l(){var a=[];null!==menusToCombine&&b.each(menusToCombine,function(b,c){a.push(c.valueOf())});b.each(genesisMenus.others,function(b,c){a.push(c.valueOf())});return 0<a.length?a:null}b.each(genesisMenusUnchecked,function(a){genesisMenus[a]=[];b.each(this,function(d,c){var f=b(c);1<f.length?b.each(f,function(d,f){var e=c+"-"+d;b(this).addClass(e.replace(".",""));genesisMenus[a].push(e);"combine"===a&&menusToCombine.push(e)}):
  15. 1==f.length&&(genesisMenus[a].push(c),"combine"===a&&menusToCombine.push(c))})});"undefined"==typeof genesisMenus.others&&(genesisMenus.others=[]);1==menusToCombine.length&&(genesisMenus.others.push(menusToCombine[0]),menusToCombine=genesisMenus.combine=null);var v={init:function(){if(0!=b(l()).length){var a="undefined"!==typeof genesisMenuParams.menuIconClass?genesisMenuParams.menuIconClass:"dashicons-before dashicons-menu",d="undefined"!==typeof genesisMenuParams.subMenuIconClass?genesisMenuParams.subMenuIconClass:
  16. "dashicons-before dashicons-arrow-down-alt2",c=b("<button />",{"class":"menu-toggle","aria-expanded":!1,"aria-pressed":!1,role:"button"}).append(genesisMenuParams.mainMenu),f=b("<button />",{"class":"sub-menu-toggle","aria-expanded":!1,"aria-pressed":!1,role:"button"}).append(b("<span />",{"class":"screen-reader-text",text:genesisMenuParams.subMenu}));b(g(genesisMenus)).addClass("genesis-responsive-menu");b(g(genesisMenus)).find(".sub-menu").before(f);null!==menusToCombine?(f=genesisMenus.others.concat(menusToCombine[0]),
  17. b(g(f)).before(c)):b(g(genesisMenus.others)).before(c);b(".menu-toggle").addClass(a);b(".sub-menu-toggle").addClass(d);b(".menu-toggle").on("click.genesisMenu-mainbutton",t).each(r);b(".sub-menu-toggle").on("click.genesisMenu-subbutton",u);b(window).on("resize.genesisMenu",n).triggerHandler("resize.genesisMenu")}}};b(m).ready(function(){null!==l()&&v.init()})})(document,jQuery);