"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,e){for(var i=0;i<e.length;i++){var a=e[i];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}return function(e,i,a){return i&&t(e.prototype,i),a&&t(e,a),e}}();!function(t){var e=function(){function e(i,a){_classCallCheck(this,e),this.$element=i,this.options=t.extend({},e.defaults,this.$element.data(),a),this._init(),Foundation.registerPlugin(this,"Tabs"),Foundation.Keyboard.register("Tabs",{ENTER:"open",SPACE:"open",ARROW_RIGHT:"next",ARROW_UP:"previous",ARROW_DOWN:"next",ARROW_LEFT:"previous"})}return _createClass(e,[{key:"_init",value:function(){var e=this;if(this.$element.attr({role:"tablist"}),this.$tabTitles=this.$element.find("."+this.options.linkClass),this.$tabContent=t('[data-tabs-content="'+this.$element[0].id+'"]'),this.$tabTitles.each(function(){var i=t(this),a=i.find("a"),n=i.hasClass(""+e.options.linkActiveClass),s=a[0].hash.slice(1),o=a[0].id?a[0].id:s+"-label",l=t("#"+s);if(i.attr({role:"presentation"}),a.attr({role:"tab","aria-controls":s,"aria-selected":n,id:o}),l.attr({role:"tabpanel","aria-hidden":!n,"aria-labelledby":o}),n&&e.options.autoFocus&&t(window).load(function(){t("html, body").animate({scrollTop:i.offset().top},e.options.deepLinkSmudgeDelay,function(){a.focus()})}),e.options.deepLink){var h=window.location.hash;if(h.length){var a=i.find('[href="'+h+'"]');a.length&&(e.selectTab(t(h)),e.options.deepLinkSmudge&&t(window).load(function(){var a=i.offset();t("html, body").animate({scrollTop:a.top},e.options.deepLinkSmudgeDelay)}),i.trigger("deeplink.zf.tabs",[a,t(h)]))}}}),this.options.matchHeight){var i=this.$tabContent.find("img");i.length?Foundation.onImagesLoaded(i,this._setHeight.bind(this)):this._setHeight()}this._events()}},{key:"_events",value:function(){this._addKeyHandler(),this._addClickHandler(),this._setHeightMqHandler=null,this.options.matchHeight&&(this._setHeightMqHandler=this._setHeight.bind(this),t(window).on("changed.zf.mediaquery",this._setHeightMqHandler))}},{key:"_addClickHandler",value:function(){var e=this;this.$element.off("click.zf.tabs").on("click.zf.tabs","."+this.options.linkClass,function(i){i.preventDefault(),i.stopPropagation(),e._handleTabChange(t(this))})}},{key:"_addKeyHandler",value:function(){var e=this;this.$tabTitles.off("keydown.zf.tabs").on("keydown.zf.tabs",function(i){if(9!==i.which){var a,n,s=t(this),o=s.parent("ul").children("li");o.each(function(i){if(t(this).is(s))return void(e.options.wrapOnKeys?(a=0===i?o.last():o.eq(i-1),n=i===o.length-1?o.first():o.eq(i+1)):(a=o.eq(Math.max(0,i-1)),n=o.eq(Math.min(i+1,o.length-1))))}),Foundation.Keyboard.handleKey(i,"Tabs",{open:function(){s.find('[role="tab"]').focus(),e._handleTabChange(s)},previous:function(){a.find('[role="tab"]').focus(),e._handleTabChange(a)},next:function(){n.find('[role="tab"]').focus(),e._handleTabChange(n)},handled:function(){i.stopPropagation(),i.preventDefault()}})}})}},{key:"_handleTabChange",value:function(t){if(t.hasClass(""+this.options.linkActiveClass))return void(this.options.activeCollapse&&(this._collapseTab(t),this.$element.trigger("collapse.zf.tabs",[t])));var e=this.$element.find("."+this.options.linkClass+"."+this.options.linkActiveClass),i=t.find('[role="tab"]'),a=i[0].hash,n=this.$tabContent.find(a);if(this._collapseTab(e),this._openTab(t),this.options.deepLink){var s=t.find("a").attr("href");this.options.updateHistory?history.pushState({},"",s):history.replaceState({},"",s)}this.$element.trigger("change.zf.tabs",[t,n]),n.find("[data-mutate]").trigger("mutateme.zf.trigger")}},{key:"_openTab",value:function(t){var e=t.find('[role="tab"]'),i=e[0].hash,a=this.$tabContent.find(i);t.addClass(""+this.options.linkActiveClass),e.attr({"aria-selected":"true"}),a.addClass(""+this.options.panelActiveClass).attr({"aria-hidden":"false"})}},{key:"_collapseTab",value:function(e){var i=e.removeClass(""+this.options.linkActiveClass).find('[role="tab"]').attr({"aria-selected":"false"});t("#"+i.attr("aria-controls")).removeClass(""+this.options.panelActiveClass).attr({"aria-hidden":"true"})}},{key:"selectTab",value:function(t){var e;e="object"==typeof t?t[0].id:t,e.indexOf("#")<0&&(e="#"+e);var i=this.$tabTitles.find('[href="'+e+'"]').parent("."+this.options.linkClass);this._handleTabChange(i)}},{key:"_setHeight",value:function(){var e=0;this.$tabContent.find("."+this.options.panelClass).css("height","").each(function(){var i=t(this),a=i.hasClass(""+this.options.panelActiveClass);a||i.css({visibility:"hidden",display:"block"});var n=this.getBoundingClientRect().height;a||i.css({visibility:"",display:""}),e=n>e?n:e}).css("height",e+"px")}},{key:"destroy",value:function(){this.$element.find("."+this.options.linkClass).off(".zf.tabs").hide().end().find("."+this.options.panelClass).hide(),this.options.matchHeight&&null!=this._setHeightMqHandler&&t(window).off("changed.zf.mediaquery",this._setHeightMqHandler),Foundation.unregisterPlugin(this)}}]),e}();e.defaults={deepLink:!1,deepLinkSmudge:!1,deepLinkSmudgeDelay:300,updateHistory:!1,autoFocus:!1,wrapOnKeys:!0,matchHeight:!1,activeCollapse:!1,linkClass:"tabs-title",linkActiveClass:"is-active",panelClass:"tabs-panel",panelActiveClass:"is-active"},Foundation.plugin(e,"Tabs")}(jQuery);
|