-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtabbedcontent.min.js
8 lines (8 loc) · 2.92 KB
/
tabbedcontent.min.js
1
2
3
4
5
6
7
8
/**
* Tabs plugin for jQuery created by Òscar Casajuana < elboletaire at underave dot net >
*
* @copyright Copyright 2013-2015 Òscar Casajuana
* @license MIT
* @author Òscar Casajuana Alonso <elboletaire at underave dot net>
*/
!function(n,t,e,r){"use strict";var i=function(i,o){function s(n){return Boolean(m.filter(n).length)}function l(){return 0===q}function a(n){return n%1===0}function c(){return q===m.length-1}function u(t){return n(this).attr("href").match(new RegExp(t+"$"))}function h(t){return t instanceof n?{tab:t,link:o.links.eq(t.index())}:a(t)?{tab:m.eq(t),link:o.links.eq(t)}:m.filter(t).length?{tab:m.filter(t),link:o.links.filter(function(){return u.apply(this,[t])})}:{tab:m.filter("#"+t),link:o.links.filter(function(){return u.apply(this,["#"+t])})}}function f(){return o.links.parent().filter("."+o.currentClass).index()}function p(n){return++q,n===r&&(n=o.loop),q<m.length?g(q,!0):n&&q>=m.length?g(0,!0):!1}function d(n){return--q,n===r&&(n=o.loop),q>=0?g(q,!0):n&&0>q?g(m.length-1,!0):!1}function k(n){o.history&&y&&x!==r&&"pushState"in x&&(y=!1,e.setTimeout(function(){x.replaceState(null,"",n)},100)),q=f(),o.onSwitch&&"function"==typeof o.onSwitch&&o.onSwitch(n,b())}function g(n,t){return n.toString().match(/^#/)||(n="#"+h(n).tab.attr("id")),s(n)?(o.links.parent().removeClass(o.currentClass),o.links.filter(function(){return u.apply(this,[n])}).parent().addClass(o.currentClass),m.hide(),o.history&&t&&(x!==r&&"pushState"in x?x.pushState(null,"",n):e.location.hash=n),m.filter(n).show(o.speed,function(){o.speed&&k(n)}),o.speed||k(n),!0):!1}function w(n){return g(n,!0)}function S(n){g(I.hash)}function v(){if(s(I.hash)?g(I.hash):o.links.parent().filter("."+o.currentClass).length?g(o.links.parent().filter("."+o.currentClass).index()):o.errorSelector&&m.find(o.errorSelector).length?m.each(function(){return n(this).find(o.errorSelector).length?(g("#"+n(this).attr("id")),!1):void 0}):g("#"+m.filter(":first-child").attr("id")),o.errorSelector&&m.find(o.errorSelector).each(function(){var t=h(n(this).parent());t.link.parent().addClass(o.tabErrorClass)}),"onhashchange"in e)n(e).bind("hashchange",S);else{var t=I.href;e.setInterval(function(){t!==I.href&&(S.call(e.event),t=I.href)},100)}n(o.links).on("click",function(t){g(n(this).attr("href").replace(/^[^#]+/,""),o.history),t.preventDefault()}),o.onInit&&"function"==typeof o.onInit&&o.onInit(b())}function b(){return{"switch":w,switchTab:w,getCurrent:f,getTab:h,next:p,prev:d,isFirst:l,isLast:c}}var C={links:i.prev().find("a").length?i.prev().find("a"):".tabs a",errorSelector:".error-message",speed:!1,onSwitch:!1,onInit:!1,currentClass:"active",tabErrorClass:"has-errors",history:!0,loop:!1},y=!0,m=i.children(),x=e.history,I=t.location,q=null;return o=n.extend(C,o),o.links instanceof n||(o.links=n(o.links)),v(),b()};n.fn.tabbedContent=function(t){return this.each(function(){var e=new i(n(this),t);n(this).data("api",e)})}}(window.jQuery||window.Zepto||window.$,document,window);