kist-tabify
Version:
Simple tabs and accordion interface.
2 lines • 10.4 kB
JavaScript
/*! kist-tabify 0.3.1 - Simple tabs and accordion interface. | Author: Ivan Nikolić <niksy5@gmail.com> (http://ivannikolic.com/), 2017 | License: MIT */
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b=b.jQuery||(b.jQuery={}),b=b.fn||(b.fn={}),b.tabify=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c||a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){var d=a(3),e=a(12),f=a(5)(e.name),g=b.exports=d.extend({toggleItem:function(a,b,c){g._super.toggleItem.apply(this,arguments),"pane"===c&&a.attr({"aria-expanded":b})},select:function(a){g._super.select.apply(this,arguments);var b=this.isAlreadyActive,c=this.options.multiSelect?"not":"filter";this.toggleItem(this.$tab[c](this.$activeTab),!1,"tab"),this.toggleItem(this.$pane[c](this.$activePane),!1,"pane"),this.toggleItem(this.$newTab,!b,"tab"),this.toggleItem(this.$newPane,!b,"pane"),this.triggerAction(a)},triggerAction:function(){g._super.triggerAction.apply(this,arguments),this.setupDone&&this.isAlreadyActive&&f(this,"deselect",[this.$newTab,this.$newPane])}})},{12:12,3:3,5:5}],2:[function(a,b,c){(function(c){function d(a){var b=a.self;return"tab"===a.type&&"-pane"===a.ns&&(a.id=b.$pane.eq(b.$tab.index(a.el)).attr("id")),"pane"===a.type&&"-tab"===a.ns&&(a.id=b.$tab.eq(b.$pane.index(a.el)).attr("id")),a.id?a.id:a.ns+"-"+b.uid+"-"+a.index}var e="undefined"!=typeof window?window.$:void 0!==c?c.$:null,f=(a(12),a(8));(b.exports=function(a){this.instance=a}).prototype.generateAttrs=function(a){var b,c=this.instance;return b="tab"===a?["aria-controls","pane"]:["aria-labelledby","tab"],function(g,h){var i,j,k=e(h),l=k.attr("id"),m=k.attr("href"),n={el:k,id:l,href:m,self:c,index:g,type:a};i=d(e.extend({},n,{ns:f[a]})),j=d(e.extend({},n,{ns:f[b[1]]})),k.attr("id",i),k.attr(b[0],j)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{12:12,8:8}],3:[function(a,b,c){(function(c){function d(a){var b=0;"next"===a&&(b=this.current===this.$tab.length-1||"number"!=typeof this.current?0:this.current+1),"prev"===a&&(b=0===this.current||"number"!=typeof this.current?this.$tab.length-1:this.current-1),this.select(b)}function e(a,b,c){var d=h(c);return d.attr("id")===a||d.data("tab-id")===a}function f(a,b,c){var d=h(c);return e.apply(null,arguments)||d.attr("href")==="#"+a}function g(a){return a.replace(/^#/,"")}var h="undefined"!=typeof window?window.$:void 0!==c?c.$:null,i=a(14),j=a(12),k=a(4),l=a(6),m=a(10),n=a(8),o=a(7),p=a(5)(j.name),q="Modernizr"in window&&window.Modernizr.history;b.exports=i.extend({constructor:function(a,b){this.element=a,this.options=h.extend(!0,{},this.defaults,b),m.setup.call(this),k.setup.call(this),l.setup.call(this),this.move(this.options.initial),this.setupDone=!0},isAlreadyActiveState:function(a,b){return!(!a.hasClass(this.options.classes.isActive)&&!b.hasClass(this.options.classes.isActive))},toggleItem:function(a,b,c){var d,e;d="tab"===c?"aria-selected":"aria-hidden",e=b?"addClass":"removeClass","pane"===c&&(b=!b),a[e](this.options.classes.isActive).attr(d,b)},select:function(a){this.$activeTab=this.$tab.filter(o(this.options.classes.isActive)),this.$activePane=this.$pane.filter(o(this.options.classes.isActive)),this.$newTab=this.$tab.eq(a),this.$newPane=this.$pane.eq(a),this.isAlreadyActive=this.isAlreadyActiveState(this.$newTab,this.$newPane),this.options.changeURL&&this.$newTab.is("a")&&q&&this.setupDone&&history.pushState({},"",this.$newTab.attr("href"))},triggerAction:function(a){if(!this.setupDone)return p(this,"create",[this.$newTab,this.$newPane]),void(this.current=a);this.isAlreadyActive||(!this.$activeTab.length&&!this.$activePane.length||this.isAlreadyActiveState(this.$activeTab,this.$activePane)||p(this,"deselect",[this.$activeTab,this.$activePane]),p(this,"select",[this.$newTab,this.$newPane]),this.current=a)},prev:function(){d.call(this,"prev")},next:function(){d.call(this,"next")},move:function(a){var b,c;"function"==typeof a&&(a=a.call(this.element)),"number"==typeof a&&this.select(a),"string"==typeof a&&(a=g(a),b=this.$tab.filter(h.proxy(f,null,a)),c=this.$pane.filter(h.proxy(e,null,a)),b.length?this.select(this.$tab.index(b[0])):c.length&&this.select(this.$pane.index(c[0]))),"boolean"==typeof a&&(a?this.select(0):p(this,"create",[h(),h()]))},destroy:function(){k.destroy.call(this),l.destroy.call(this),m.destroy.call(this)},current:null,setupDone:!1,defaults:{type:"tab",initial:0,multiSelect:!1,tab:"> ul > li > a, > ul > li > button",pane:"> div > div",changeURL:!1,select:h.noop,deselect:h.noop,create:h.noop,classes:n}})}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{10:10,12:12,14:14,4:4,5:5,6:6,7:7,8:8}],4:[function(a,b,c){(function(c){var d="undefined"!=typeof window?window.$:void 0!==c?c.$:null,e=(a(12),a(8),a(2)),f=b.exports={$body:d("body"),setup:function(){var a=new e(this),b=a.generateAttrs("tab"),c=a.generateAttrs("pane");f.$body=f.$body.length?f.$body:d("body"),this.$el=d(this.element),this.$tab=this.$el.find(this.options.tab),this.$pane=this.$el.find(this.options.pane),this.$pane=this.$pane.length?this.$pane:f.$body.find(this.options.pane),this.$tabItem=this.$tab.closest("li"),this.$tabItem=this.$el.find(this.$tabItem).length?this.$tabItem:d(),this.$tabList=this.$tab.closest("ul"),this.$tabList=this.$el.find(this.$tabList).length?this.$tabList:d(),this.$el.addClass(this.options.classes.wrapper),this.$tab.addClass(this.options.classes.tab).attr({role:"tab","aria-selected":!1}).each(b),this.$pane.addClass(this.options.classes.pane).attr({role:"tabpanel","aria-hidden":!0}).each(c),this.$tabItem.attr({role:"presentation"}),this.$tabList.attr({role:"tablist"}),"accordion"===this.options.type&&(this.$pane.attr({"aria-expanded":!1}),this.options.multiSelect&&this.$el.attr({"aria-multiselectable":!0}))},destroy:function(){this.$el.removeClass(this.options.classes.wrapper).removeAttr("aria-multiselectable"),this.$tab.removeClass(this.options.classes.tab).removeClass(this.options.classes.isActive).removeAttr("role aria-selected aria-controls"),this.$pane.removeClass(this.options.classes.pane).removeClass(this.options.classes.isActive).removeAttr("role aria-hidden aria-labelledby aria-expanded"),this.$tabItem.add(this.$tabList).removeAttr("role"),this.$tab.add(this.$pane).each(function(a,b){var c=d(this);/^kist-/.test(c.attr("id"))&&c.removeAttr("id")})}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{12:12,2:2,8:8}],5:[function(a,b,c){(function(a){var c="undefined"!=typeof window?window.$:void 0!==a?a.$:null;b.exports=function(a){return function(b,d,e,f){var g=b.dom&&b.dom.el||b.$el||c({});b.options[d]&&b.options[d].apply(1===g.length?g[0]:g.toArray(),e),(f||g).trigger(((a||"")+d).toLowerCase(),e)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],6:[function(a,b,c){(function(c){var d="undefined"!=typeof window?window.$:void 0!==c?c.$:null,e=a(7);b.exports={setup:function(){this.$el.on("click"+this.ens,e(this.options.classes.tab),d.proxy(function(a){a.preventDefault(),this.select(this.$tab.index(d(a.currentTarget)))},this))},destroy:function(){this.$el.off(this.ens)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{7:7}],7:[function(a,b,c){b.exports=function(a){return"."+a.split(" ").join(".")}},{}],8:[function(a,b,c){var d=a(12),e=d.ns.htmlClass;b.exports={wrapper:e,tab:e+"-tab",pane:e+"-pane",isActive:"is-active"}},{12:12}],9:[function(a,b,c){(function(c){var d="undefined"!=typeof window?window.$:void 0!==c?c.$:null,e=a(3),f=a(13),g=a(1),h=a(12),i=a(11)(h.publicMethods);(d.fn[h.name]=b.exports=function(a,b){return a=a||{},this.each(function(){var c=d.data(this,h.name);if(i(a)&&c)c[a]("move"===a?b:void 0);else if("object"==typeof a&&!c){var e="accordion"===a.type?g:f;d.data(this,h.name,new e(this,a))}})}).defaults=e.prototype.defaults}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{1:1,11:11,12:12,13:13,3:3}],10:[function(a,b,c){(function(c){var d="undefined"!=typeof window?window.$:void 0!==c?c.$:null,e=a(12),f=0;b.exports={setup:function(){this.uid=f++,this.ens=e.ns.event+"."+this.uid},destroy:function(){d.removeData(this.element,e.name)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{12:12}],11:[function(a,b,c){(function(a){var c="undefined"!=typeof window?window.$:void 0!==a?a.$:null;b.exports=function(a){return function(b){return"string"==typeof b&&-1!==c.inArray(b,a||[])}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],12:[function(a,b,c){b.exports={name:"tabify",ns:{htmlClass:"kist-Tabify",event:".kist.tabify"},publicMethods:["destroy","prev","next","move"]}},{}],13:[function(a,b,c){var d=a(3),e=b.exports=d.extend({select:function(a){e._super.select.apply(this,arguments),this.toggleItem(this.$tab,!1,"tab"),this.toggleItem(this.$pane,!1,"pane"),this.toggleItem(this.$newTab,!0,"tab"),this.toggleItem(this.$newPane,!0,"pane"),this.triggerAction(a)}})},{3:3}],14:[function(a,b,c){function d(a,b){function c(){}var d,f=this;return d=a&&a.hasOwnProperty("constructor")?a.constructor:function(){d._super.constructor.apply(this,arguments)},e(d,f,b),c.prototype=f.prototype,d.prototype=new c,d.prototype.constructor=d,d._super=f.prototype,a&&e(d.prototype,a),d}var e=a(15);(b.exports=function(){}).extend=d},{15:15}],15:[function(a,b,c){function d(a){for(var b=1;b<arguments.length;b++){var c=arguments[b];for(var d in c)e.call(c,d)&&(a[d]=c[d])}return a}b.exports=d;var e=Object.prototype.hasOwnProperty},{}]},{},[9])(9)});