"use strict";function _classCallCheck(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function n(n,e){for(var i=0;i<e.length;i++){var t=e[i];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(n,t.key,t)}}return function(e,i,t){return i&&n(e.prototype,i),t&&n(e,t),e}}();!function(n){var e=function(){function e(i,t){_classCallCheck(this,e),this.$element=i,this.options=n.extend({},e.defaults,this.$element.data(),t),Foundation.Nest.Feather(this.$element,"accordion"),this._init(),Foundation.registerPlugin(this,"AccordionMenu"),Foundation.Keyboard.register("AccordionMenu",{ENTER:"toggle",SPACE:"toggle",ARROW_RIGHT:"open",ARROW_UP:"up",ARROW_DOWN:"down",ARROW_LEFT:"close",ESCAPE:"closeAll"})}return _createClass(e,[{key:"_init",value:function(){this.$element.find("[data-submenu]").not(".is-active").slideUp(0),this.$element.attr({role:"menu","aria-multiselectable":this.options.multiOpen}),this.$menuLinks=this.$element.find(".is-accordion-submenu-parent"),this.$menuLinks.each(function(){var e=this.id||Foundation.GetYoDigits(6,"acc-menu-link"),i=n(this),t=i.children("[data-submenu]"),a=t[0].id||Foundation.GetYoDigits(6,"acc-menu"),s=t.hasClass("is-active");i.attr({"aria-controls":a,"aria-expanded":s,role:"menuitem",id:e}),t.attr({"aria-labelledby":e,"aria-hidden":!s,role:"menu",id:a})});var e=this.$element.find(".is-active");if(e.length){var i=this;e.each(function(){i.down(n(this))})}this._events()}},{key:"_events",value:function(){var e=this;this.$element.find("li").each(function(){var i=n(this).children("[data-submenu]");i.length&&n(this).children("a").off("click.zf.accordionMenu").on("click.zf.accordionMenu",function(n){n.preventDefault(),e.toggle(i)})}).on("keydown.zf.accordionmenu",function(i){var t,a,s=n(this),o=s.parent("ul").children("li"),d=s.children("[data-submenu]");o.each(function(e){if(n(this).is(s))return t=o.eq(Math.max(0,e-1)).find("a").first(),a=o.eq(Math.min(e+1,o.length-1)).find("a").first(),n(this).children("[data-submenu]:visible").length&&(a=s.find("li:first-child").find("a").first()),n(this).is(":first-child")?t=s.parents("li").first().find("a").first():t.parents("li").first().children("[data-submenu]:visible").length&&(t=t.parents("li").find("li:last-child").find("a").first()),void(n(this).is(":last-child")&&(a=s.parents("li").first().next("li").find("a").first()))}),Foundation.Keyboard.handleKey(i,"AccordionMenu",{open:function(){d.is(":hidden")&&(e.down(d),d.find("li").first().find("a").first().focus())},close:function(){d.length&&!d.is(":hidden")?e.up(d):s.parent("[data-submenu]").length&&(e.up(s.parent("[data-submenu]")),s.parents("li").first().find("a").first().focus())},up:function(){return t.focus(),!0},down:function(){return a.focus(),!0},toggle:function(){s.children("[data-submenu]").length&&e.toggle(s.children("[data-submenu]"))},closeAll:function(){e.hideAll()},handled:function(n){n&&i.preventDefault(),i.stopImmediatePropagation()}})})}},{key:"hideAll",value:function(){this.up(this.$element.find("[data-submenu]"))}},{key:"showAll",value:function(){this.down(this.$element.find("[data-submenu]"))}},{key:"toggle",value:function(n){n.is(":animated")||(n.is(":hidden")?this.down(n):this.up(n))}},{key:"down",value:function(n){var e=this;this.options.multiOpen||this.up(this.$element.find(".is-active").not(n.parentsUntil(this.$element).add(n))),n.addClass("is-active").attr({"aria-hidden":!1}).parent(".is-accordion-submenu-parent").attr({"aria-expanded":!0}),n.slideDown(e.options.slideSpeed,function(){e.$element.trigger("down.zf.accordionMenu",[n])})}},{key:"up",value:function(n){var e=this;n.slideUp(e.options.slideSpeed,function(){e.$element.trigger("up.zf.accordionMenu",[n])});var i=n.find("[data-submenu]").slideUp(0).addBack().attr("aria-hidden",!0);i.parent(".is-accordion-submenu-parent").attr("aria-expanded",!1)}},{key:"destroy",value:function(){this.$element.find("[data-submenu]").slideDown(0).css("display",""),this.$element.find("a").off("click.zf.accordionMenu"),Foundation.Nest.Burn(this.$element,"accordion"),Foundation.unregisterPlugin(this)}}]),e}();e.defaults={slideSpeed:250,multiOpen:!0},Foundation.plugin(e,"AccordionMenu")}(jQuery);
|