"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,n){for(var t=0;t<n.length;t++){var i=n[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(n,t,i){return t&&e(n.prototype,t),i&&e(n,i),n}}();!function(e){var n=function(){function n(t,i){_classCallCheck(this,n),this.$element=t,this.options=e.extend({},n.defaults,this.$element.data(),i),Foundation.Nest.Feather(this.$element,"drilldown"),this._init(),Foundation.registerPlugin(this,"Drilldown"),Foundation.Keyboard.register("Drilldown",{ENTER:"open",SPACE:"open",ARROW_RIGHT:"next",ARROW_UP:"up",ARROW_DOWN:"down",ARROW_LEFT:"previous",ESCAPE:"close",TAB:"down",SHIFT_TAB:"up"})}return _createClass(n,[{key:"_init",value:function(){this.$submenuAnchors=this.$element.find("li.is-drilldown-submenu-parent").children("a"),this.$submenus=this.$submenuAnchors.parent("li").children("[data-submenu]"),this.$menuItems=this.$element.find("li").not(".js-drilldown-back").attr("role","menuitem").find("a"),this.$element.attr("data-mutate",this.$element.attr("data-drilldown")||Foundation.GetYoDigits(6,"drilldown")),this._prepareMenu(),this._registerEvents(),this._keyboardEvents()}},{key:"_prepareMenu",value:function(){var n=this;this.$submenuAnchors.each(function(){var t=e(this),i=t.parent();n.options.parentLink&&t.clone().prependTo(i.children("[data-submenu]")).wrap('<li class="is-submenu-parent-item is-submenu-item is-drilldown-submenu-item" role="menu-item"></li>'),t.data("savedHref",t.attr("href")).removeAttr("href").attr("tabindex",0),t.children("[data-submenu]").attr({"aria-hidden":!0,tabindex:0,role:"menu"}),n._events(t)}),this.$submenus.each(function(){var t=e(this),i=t.find(".js-drilldown-back");if(!i.length)switch(n.options.backButtonPosition){case"bottom":t.append(n.options.backButton);break;case"top":t.prepend(n.options.backButton);break;default:console.error("Unsupported backButtonPosition value '"+n.options.backButtonPosition+"'")}n._back(t)}),this.options.autoHeight||this.$submenus.addClass("drilldown-submenu-cover-previous"),this.$element.parent().hasClass("is-drilldown")||(this.$wrapper=e(this.options.wrapper).addClass("is-drilldown"),this.options.animateHeight&&this.$wrapper.addClass("animate-height"),this.$wrapper=this.$element.wrap(this.$wrapper).parent().css(this._getMaxDims()))}},{key:"_resize",value:function(){this.$wrapper.css({"max-width":"none","min-height":"none"}),this.$wrapper.css(this._getMaxDims())}},{key:"_events",value:function(n){var t=this;n.off("click.zf.drilldown").on("click.zf.drilldown",function(i){if(e(i.target).parentsUntil("ul","li").hasClass("is-drilldown-submenu-parent")&&(i.stopImmediatePropagation(),i.preventDefault()),t._show(n.parent("li")),t.options.closeOnClick){var s=e("body");s.off(".zf.drilldown").on("click.zf.drilldown",function(n){n.target===t.$element[0]||e.contains(t.$element[0],n.target)||(n.preventDefault(),t._hideAll(),s.off(".zf.drilldown"))})}}),this.$element.on("mutateme.zf.trigger",this._resize.bind(this))}},{key:"_registerEvents",value:function(){this.options.scrollTop&&(this._bindHandler=this._scrollTop.bind(this),this.$element.on("open.zf.drilldown hide.zf.drilldown closed.zf.drilldown",this._bindHandler))}},{key:"_scrollTop",value:function(){var n=this,t=""!=n.options.scrollTopElement?e(n.options.scrollTopElement):n.$element,i=parseInt(t.offset().top+n.options.scrollTopOffset);e("html, body").stop(!0).animate({scrollTop:i},n.options.animationDuration,n.options.animationEasing,function(){this===e("html")[0]&&n.$element.trigger("scrollme.zf.drilldown")})}},{key:"_keyboardEvents",value:function(){var n=this;this.$menuItems.add(this.$element.find(".js-drilldown-back > a, .is-submenu-parent-item > a")).on("keydown.zf.drilldown",function(t){var i,s,o=e(this),a=o.parent("li").parent("ul").children("li").children("a");a.each(function(n){if(e(this).is(o))return i=a.eq(Math.max(0,n-1)),void(s=a.eq(Math.min(n+1,a.length-1)))}),Foundation.Keyboard.handleKey(t,"Drilldown",{next:function(){if(o.is(n.$submenuAnchors))return n._show(o.parent("li")),o.parent("li").one(Foundation.transitionend(o),function(){o.parent("li").find("ul li a").filter(n.$menuItems).first().focus()}),!0},previous:function(){return n._hide(o.parent("li").parent("ul")),o.parent("li").parent("ul").one(Foundation.transitionend(o),function(){setTimeout(function(){o.parent("li").parent("ul").parent("li").children("a").first().focus()},1)}),!0},up:function(){return i.focus(),!0},down:function(){return s.focus(),!0},close:function(){n._back()},open:function(){return o.is(n.$menuItems)?o.is(n.$submenuAnchors)?(n._show(o.parent("li")),o.parent("li").one(Foundation.transitionend(o),function(){o.parent("li").find("ul li a").filter(n.$menuItems).first().focus()}),!0):void 0:(n._hide(o.parent("li").parent("ul")),o.parent("li").parent("ul").one(Foundation.transitionend(o),function(){setTimeout(function(){o.parent("li").parent("ul").parent("li").children("a").first().focus()},1)}),!0)},handled:function(e){e&&t.preventDefault(),t.stopImmediatePropagation()}})})}},{key:"_hideAll",value:function(){var e=this.$element.find(".is-drilldown-submenu.is-active").addClass("is-closing");this.options.autoHeight&&this.$wrapper.css({height:e.parent().closest("ul").data("calcHeight")}),e.one(Foundation.transitionend(e),function(n){e.removeClass("is-active is-closing")}),this.$element.trigger("closed.zf.drilldown")}},{key:"_back",value:function(e){var n=this;e.off("click.zf.drilldown"),e.children(".js-drilldown-back").on("click.zf.drilldown",function(t){t.stopImmediatePropagation(),n._hide(e);var i=e.parent("li").parent("ul").parent("li");i.length&&n._show(i)})}},{key:"_menuLinkEvents",value:function(){var e=this;this.$menuItems.not(".is-drilldown-submenu-parent").off("click.zf.drilldown").on("click.zf.drilldown",function(n){setTimeout(function(){e._hideAll()},0)})}},{key:"_show",value:function(e){this.options.autoHeight&&this.$wrapper.css({height:e.children("[data-submenu]").data("calcHeight")}),e.attr("aria-expanded",!0),e.children("[data-submenu]").addClass("is-active").attr("aria-hidden",!1),this.$element.trigger("open.zf.drilldown",[e])}},{key:"_hide",value:function(e){this.options.autoHeight&&this.$wrapper.css({height:e.parent().closest("ul").data("calcHeight")});e.parent("li").attr("aria-expanded",!1),e.attr("aria-hidden",!0).addClass("is-closing"),e.addClass("is-closing").one(Foundation.transitionend(e),function(){e.removeClass("is-active is-closing"),e.blur()}),e.trigger("hide.zf.drilldown",[e])}},{key:"_getMaxDims",value:function(){var n=0,t={},i=this;return this.$submenus.add(this.$element).each(function(){var s=(e(this).children("li").length,Foundation.Box.GetDimensions(this).height);n=s>n?s:n,i.options.autoHeight&&(e(this).data("calcHeight",s),e(this).hasClass("is-drilldown-submenu")||(t.height=s))}),this.options.autoHeight||(t["min-height"]=n+"px"),t["max-width"]=this.$element[0].getBoundingClientRect().width+"px",t}},{key:"destroy",value:function(){this.options.scrollTop&&this.$element.off(".zf.drilldown",this._bindHandler),this._hideAll(),this.$element.off("mutateme.zf.trigger"),Foundation.Nest.Burn(this.$element,"drilldown"),this.$element.unwrap().find(".js-drilldown-back, .is-submenu-parent-item").remove().end().find(".is-active, .is-closing, .is-drilldown-submenu").removeClass("is-active is-closing is-drilldown-submenu").end().find("[data-submenu]").removeAttr("aria-hidden tabindex role"),this.$submenuAnchors.each(function(){e(this).off(".zf.drilldown")}),this.$submenus.removeClass("drilldown-submenu-cover-previous"),this.$element.find("a").each(function(){var n=e(this);n.removeAttr("tabindex"),n.data("savedHref")&&n.attr("href",n.data("savedHref")).removeData("savedHref")}),Foundation.unregisterPlugin(this)}}]),n}();n.defaults={backButton:'<li class="js-drilldown-back"><a tabindex="0">Back</a></li>',backButtonPosition:"top",wrapper:"<div></div>",parentLink:!1,closeOnClick:!1,autoHeight:!1,animateHeight:!1,scrollTop:!1,scrollTopElement:"",scrollTopOffset:0,animationDuration:500,animationEasing:"swing"},Foundation.plugin(n,"Drilldown")}(jQuery);
|