"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 a=0;a<e.length;a++){var i=e[a];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,a,i){return a&&t(e.prototype,a),i&&t(e,i),e}}();!function(t){var e=function(){function e(a,i){_classCallCheck(this,e),this.$element=t(a),this.options=t.extend({},this.$element.data(),i),this.rules=this.$element.data("responsive-accordion-tabs"),this.currentMq=null,this.currentPlugin=null,this.$element.attr("id")||this.$element.attr("id",Foundation.GetYoDigits(6,"responsiveaccordiontabs")),this._init(),this._events(),Foundation.registerPlugin(this,"ResponsiveAccordionTabs")}return _createClass(e,[{key:"_init",value:function(){if("string"==typeof this.rules){for(var e={},i=this.rules.split(" "),n=0;n<i.length;n++){var s=i[n].split("-"),r=s.length>1?s[0]:"small",l=s.length>1?s[1]:s[0];null!==a[l]&&(e[r]=a[l])}this.rules=e}this._getAllOptions(),t.isEmptyObject(this.rules)||this._checkMediaQueries()}},{key:"_getAllOptions",value:function(){var e=this;e.allOptions={};for(var i in a)if(a.hasOwnProperty(i)){var n=a[i];try{var s=t("<ul></ul>"),r=new n.plugin(s,e.options);for(var l in r.options)if(r.options.hasOwnProperty(l)&&"zfPlugin"!==l){var o=r.options[l];e.allOptions[l]=o}r.destroy()}catch(t){}}}},{key:"_events",value:function(){var e=this;t(window).on("changed.zf.mediaquery",function(){e._checkMediaQueries()})}},{key:"_checkMediaQueries",value:function(){var e,i=this;t.each(this.rules,function(t){Foundation.MediaQuery.atLeast(t)&&(e=t)}),e&&(this.currentPlugin instanceof this.rules[e].plugin||(t.each(a,function(t,e){i.$element.removeClass(e.cssClass)}),this.$element.addClass(this.rules[e].cssClass),this.currentPlugin&&(!this.currentPlugin.$element.data("zfPlugin")&&this.storezfData&&this.currentPlugin.$element.data("zfPlugin",this.storezfData),this.currentPlugin.destroy()),this._handleMarkup(this.rules[e].cssClass),this.currentPlugin=new this.rules[e].plugin(this.$element,{}),this.storezfData=this.currentPlugin.$element.data("zfPlugin")))}},{key:"_handleMarkup",value:function(e){var a=this,i="accordion",n=t("[data-tabs-content="+this.$element.attr("id")+"]");if(n.length&&(i="tabs"),i!==e){var s=a.allOptions.linkClass?a.allOptions.linkClass:"tabs-title",r=a.allOptions.panelClass?a.allOptions.panelClass:"tabs-panel";this.$element.removeAttr("role");var l=this.$element.children("."+s+",[data-accordion-item]").removeClass(s).removeClass("accordion-item").removeAttr("data-accordion-item"),o=l.children("a").removeClass("accordion-title");if("tabs"===i?(n=n.children("."+r).removeClass(r).removeAttr("role").removeAttr("aria-hidden").removeAttr("aria-labelledby"),n.children("a").removeAttr("role").removeAttr("aria-controls").removeAttr("aria-selected")):n=l.children("[data-tab-content]").removeClass("accordion-content"),n.css({display:"",visibility:""}),l.css({display:"",visibility:""}),"accordion"===e)n.each(function(e,i){t(i).appendTo(l.get(e)).addClass("accordion-content").attr("data-tab-content","").removeClass("is-active").css({height:""}),t("[data-tabs-content="+a.$element.attr("id")+"]").after('<div id="tabs-placeholder-'+a.$element.attr("id")+'"></div>').remove(),l.addClass("accordion-item").attr("data-accordion-item",""),o.addClass("accordion-title")});else if("tabs"===e){var c=t("[data-tabs-content="+a.$element.attr("id")+"]"),d=t("#tabs-placeholder-"+a.$element.attr("id"));d.length?(c=t('<div class="tabs-content"></div>').insertAfter(d).attr("data-tabs-content",a.$element.attr("id")),d.remove()):c=t('<div class="tabs-content"></div>').insertAfter(a.$element).attr("data-tabs-content",a.$element.attr("id")),n.each(function(e,a){var i=t(a).appendTo(c).addClass(r),n=o.get(e).hash.slice(1),s=t(a).attr("id")||Foundation.GetYoDigits(6,"accordion");n!==s&&(""!==n?t(a).attr("id",n):(n=s,t(a).attr("id",n),t(o.get(e)).attr("href",t(o.get(e)).attr("href").replace("#","")+"#"+n)));var d=t(l.get(e)).hasClass("is-active");d&&i.addClass("is-active")}),l.addClass(s)}}}},{key:"destroy",value:function(){this.currentPlugin&&this.currentPlugin.destroy(),t(window).off(".zf.ResponsiveAccordionTabs"),Foundation.unregisterPlugin(this)}}]),e}();e.defaults={};var a={tabs:{cssClass:"tabs",plugin:Foundation._plugins.tabs||null},accordion:{cssClass:"accordion",plugin:Foundation._plugins.accordion||null}};Foundation.plugin(e,"ResponsiveAccordionTabs")}(jQuery);
|