UNPKG

foundation-sites

Version:

The most advanced responsive front-end framework in the world.

3 lines (2 loc) 10.3 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("./foundation.core"),require("./foundation.util.imageLoader"),require("./foundation.util.keyboard"),require("jquery")):"function"==typeof define&&define.amd?define(["./foundation.core","./foundation.util.imageLoader","./foundation.util.keyboard","jquery"],e):"object"==typeof exports?exports["foundation.tabs"]=e(require("./foundation.core"),require("./foundation.util.imageLoader"),require("./foundation.util.keyboard"),require("jquery")):(t.__FOUNDATION_EXTERNAL__=t.__FOUNDATION_EXTERNAL__||{},t.__FOUNDATION_EXTERNAL__["foundation.tabs"]=e(t.__FOUNDATION_EXTERNAL__["foundation.core"],t.__FOUNDATION_EXTERNAL__["foundation.util.imageLoader"],t.__FOUNDATION_EXTERNAL__["foundation.util.keyboard"],t.jQuery))}(window,function(n,i,o,a){return r={"./foundation.core":function(t,e){t.exports=n},"./foundation.util.imageLoader":function(t,e){t.exports=i},"./foundation.util.keyboard":function(t,e){t.exports=o},"./js/entries/plugins/foundation.tabs.js":function(t,e,n){"use strict";n.r(e);var i=n("./foundation.core");n.d(e,"Foundation",function(){return i.Foundation});var o=n("./js/foundation.tabs.js");n.d(e,"Tabs",function(){return o.Tabs}),i.Foundation.plugin(o.Tabs,"Tabs")},"./js/foundation.tabs.js":function(t,e,n){"use strict";n.r(e),n.d(e,"Tabs",function(){return i});var e=n("jquery"),r=n.n(e),c=n("./foundation.core"),s=n("./foundation.util.keyboard"),a=n("./foundation.util.imageLoader");function l(t){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function u(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function d(n){var i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}();return function(){var t,e=o(n);return function(t,e){{if(e&&("object"===l(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined")}return function(t){if(void 0!==t)return t;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}(t)}(this,i?(t=o(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments))}}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var i=function(){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}(o,c["Plugin"]);var t,e,n,i=d(o);function o(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o),i.apply(this,arguments)}return t=o,(e=[{key:"_setup",value:function(t,e){this.$element=t,this.options=r.a.extend({},o.defaults,this.$element.data(),e),this.className="Tabs",this._init(),s.Keyboard.register("Tabs",{ENTER:"open",SPACE:"open",ARROW_RIGHT:"next",ARROW_UP:"previous",ARROW_DOWN:"next",ARROW_LEFT:"previous"})}},{key:"_init",value:function(){var t,i=this,s=this;this._isInitializing=!0,this.$element.attr({role:"tablist"}),this.$tabTitles=this.$element.find(".".concat(this.options.linkClass)),this.$tabContent=r()('[data-tabs-content="'.concat(this.$element[0].id,'"]')),this.$tabTitles.each(function(){var t=r()(this),e=t.find("a"),n=t.hasClass("".concat(s.options.linkActiveClass)),i=e.attr("data-tabs-target")||e[0].hash.slice(1),o=e[0].id||"".concat(i,"-label"),a=r()("#".concat(i));t.attr({role:"presentation"}),e.attr({role:"tab","aria-controls":i,"aria-selected":n,id:o,tabindex:n?"0":"-1"}),a.attr({role:"tabpanel","aria-labelledby":o}),n&&(s._initialAnchor="#".concat(i)),n||a.attr("aria-hidden","true"),n&&s.options.autoFocus&&(s.onLoadListener=Object(c.onLoad)(r()(window),function(){r()("html, body").animate({scrollTop:t.offset().top},s.options.deepLinkSmudgeDelay,function(){e.focus()})}))}),this.options.matchHeight&&((t=this.$tabContent.find("img")).length?Object(a.onImagesLoaded)(t,this._setHeight.bind(this)):this._setHeight()),this._checkDeepLink=function(){var t=window.location.hash;if(!t.length){if(i._isInitializing)return;i._initialAnchor&&(t=i._initialAnchor)}var e=0<=t.indexOf("#")?t.slice(1):t,n=e&&r()("#".concat(e)),t=t&&i.$element.find('[href$="'.concat(t,'"],[data-tabs-target="').concat(e,'"]')).first();!n.length||!t.length||(n&&n.length&&t&&t.length?i.selectTab(n,!0):i._collapse(),i.options.deepLinkSmudge&&(e=i.$element.offset(),r()("html, body").animate({scrollTop:e.top-i.options.deepLinkSmudgeOffset},i.options.deepLinkSmudgeDelay)),i.$element.trigger("deeplink.zf.tabs",[t,n]))},this.options.deepLink&&this._checkDeepLink(),this._events(),this._isInitializing=!1}},{key:"_events",value:function(){this._addKeyHandler(),this._addClickHandler(),this._setHeightMqHandler=null,this.options.matchHeight&&(this._setHeightMqHandler=this._setHeight.bind(this),r()(window).on("changed.zf.mediaquery",this._setHeightMqHandler)),this.options.deepLink&&r()(window).on("hashchange",this._checkDeepLink)}},{key:"_addClickHandler",value:function(){var e=this;this.$element.off("click.zf.tabs").on("click.zf.tabs",".".concat(this.options.linkClass),function(t){t.preventDefault(),e._handleTabChange(r()(this))})}},{key:"_addKeyHandler",value:function(){var a=this;this.$tabTitles.off("keydown.zf.tabs").on("keydown.zf.tabs",function(t){var e,n,i,o;9!==t.which&&(e=r()(this),(n=e.parent("ul").children("li")).each(function(t){r()(this).is(e)&&(o=a.options.wrapOnKeys?(i=0===t?n.last():n.eq(t-1),t===n.length-1?n.first():n.eq(t+1)):(i=n.eq(Math.max(0,t-1)),n.eq(Math.min(t+1,n.length-1))))}),s.Keyboard.handleKey(t,"Tabs",{open:function(){e.find('[role="tab"]').focus(),a._handleTabChange(e)},previous:function(){i.find('[role="tab"]').focus(),a._handleTabChange(i)},next:function(){o.find('[role="tab"]').focus(),a._handleTabChange(o)},handled:function(){t.preventDefault()}}))})}},{key:"_handleTabChange",value:function(t,e){var n,i,o;t.hasClass("".concat(this.options.linkActiveClass))?this.options.activeCollapse&&this._collapse():(n=this.$element.find(".".concat(this.options.linkClass,".").concat(this.options.linkActiveClass)),i=(i=(o=t.find('[role="tab"]')).attr("data-tabs-target"))&&i.length?"#".concat(i):o[0].hash,o=this.$tabContent.find(i),this._collapseTab(n),this._openTab(t),this.options.deepLink&&!e&&(this.options.updateHistory?history.pushState({},"",i):history.replaceState({},"",i)),this.$element.trigger("change.zf.tabs",[t,o]),o.find("[data-mutate]").trigger("mutateme.zf.trigger"))}},{key:"_openTab",value:function(t){var e=t.find('[role="tab"]'),n=e.attr("data-tabs-target")||e[0].hash.slice(1),n=this.$tabContent.find("#".concat(n));t.addClass("".concat(this.options.linkActiveClass)),e.attr({"aria-selected":"true",tabindex:"0"}),n.addClass("".concat(this.options.panelActiveClass)).removeAttr("aria-hidden")}},{key:"_collapseTab",value:function(t){t=t.removeClass("".concat(this.options.linkActiveClass)).find('[role="tab"]').attr({"aria-selected":"false",tabindex:-1});r()("#".concat(t.attr("aria-controls"))).removeClass("".concat(this.options.panelActiveClass)).attr({"aria-hidden":"true"})}},{key:"_collapse",value:function(){var t=this.$element.find(".".concat(this.options.linkClass,".").concat(this.options.linkActiveClass));t.length&&(this._collapseTab(t),this.$element.trigger("collapse.zf.tabs",[t]))}},{key:"selectTab",value:function(t,e){var n,t="object"===l(t)?t[0].id:t;t.indexOf("#")<0?n="#".concat(t):t=(n=t).slice(1);t=this.$tabTitles.has('[href$="'.concat(n,'"],[data-tabs-target="').concat(t,'"]')).first();this._handleTabChange(t,e)}},{key:"_setHeight",value:function(){var i=0,o=this;this.$tabContent&&this.$tabContent.find(".".concat(this.options.panelClass)).css("min-height","").each(function(){var t=r()(this),e=t.hasClass("".concat(o.options.panelActiveClass));e||t.css({visibility:"hidden",display:"block"});var n=this.getBoundingClientRect().height;e||t.css({visibility:"",display:""}),i=i<n?n:i}).css("min-height","".concat(i,"px"))}},{key:"_destroy",value:function(){this.$element.find(".".concat(this.options.linkClass)).off(".zf.tabs").hide().end().find(".".concat(this.options.panelClass)).hide(),this.options.matchHeight&&null!=this._setHeightMqHandler&&r()(window).off("changed.zf.mediaquery",this._setHeightMqHandler),this.options.deepLink&&r()(window).off("hashchange",this._checkDeepLink),this.onLoadListener&&r()(window).off(this.onLoadListener)}}])&&u(t.prototype,e),n&&u(t,n),o}();i.defaults={deepLink:!1,deepLinkSmudge:!1,deepLinkSmudgeDelay:300,deepLinkSmudgeOffset:0,updateHistory:!1,autoFocus:!1,wrapOnKeys:!0,matchHeight:!1,activeCollapse:!1,linkClass:"tabs-title",linkActiveClass:"is-active",panelClass:"tabs-panel",panelActiveClass:"is-active"}},18:function(t,e,n){t.exports=n("./js/entries/plugins/foundation.tabs.js")},jquery:function(t,e){t.exports=a}},c={},s.m=r,s.c=c,s.d=function(t,e,n){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)s.d(n,i,function(t){return e[t]}.bind(null,i));return n},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=18);function s(t){if(c[t])return c[t].exports;var e=c[t]={i:t,l:!1,exports:{}};return r[t].call(e.exports,e,e.exports,s),e.l=!0,e.exports}var r,c}); //# sourceMappingURL=foundation.tabs.min.js.map