/** * Tabs plugin for jQuery created by Òscar Casajuana < elboletaire at underave dot net > * * @copyright Copyright 2013-2016 Òscar Casajuana * @license MIT * @author Òscar Casajuana Alonso */ !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?k(0,!0):!1}function d(n){return--q,n===r&&(n=o.loop),q>=0?k(q,!0):n&&0>q?k(m.length-1,!0):!1}function g(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()),i.trigger("onSwitch",[n,b()])}function k(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&&g(n)}),o.speed||g(n),!0):!1}function w(n){return k(n,!0)}function S(n){k(I.hash)}function v(){if(s(I.hash)?k(I.hash):o.links.parent().filter("."+o.currentClass).length?k(o.links.parent().filter("."+o.currentClass).index()):o.errorSelector&&m.find(o.errorSelector).length?m.each(function(){return n(this).find(o.errorSelector).length?(k("#"+n(this).attr("id")),!1):void 0}):k("#"+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){k(n(this).attr("href").replace(/^[^#]+/,""),o.history),t.preventDefault()}),o.onInit&&"function"==typeof o.onInit&&o.onInit(b()),i.trigger("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);